Make sure to set the working directory in the above code chunk

Read in data

out.df <- read.table(file = "summary_20220428_20220726.txt", header=TRUE)
head(out.df)
##      seed n_samp_tot n_samp_per_pop sd_fitness_among_inds sd_fitness_among_pops
## 1 1231094       1000             10            0.05272602            0.01977273
## 2 1231095       1000             10            0.04519923            0.01541145
## 3 1231096       1000             10            0.05348903            0.02022721
## 4 1231097       1000             10            0.05446050            0.01731323
## 5 1231098       1000             10            0.05093029            0.01832588
## 6 1231099       1000             10            0.07552882            0.02341833
##   final_LA K   Bonf_alpha numCausalLowMAFsample all_corr_phen_temp
## 1 0.500854 2 1.918428e-06                    39          0.9545790
## 2 0.505075 9 1.730523e-06                   104          0.9545764
## 3 0.499265 9 1.508614e-06                    22          0.9723022
## 4 0.499365 9 1.531065e-06                    24          0.9720233
## 5 0.501054 6 6.395498e-06                    12          0.9708565
## 6 0.478131 3 2.022981e-06                    34          0.9247450
##   subsamp_corr_phen_temp all_corr_phen_sal subsamp_corr_phen_sal
## 1              0.8893387                NA                    NA
## 2              0.9006961                NA                    NA
## 3              0.8873320                NA                    NA
## 4              0.8895298                NA                    NA
## 5              0.8921410                NA                    NA
## 6              0.8525464                NA                    NA
##   num_causal_prefilter num_causal_postfilter num_non_causal num_neut_prefilter
## 1                 2628                   310          25753              26587
## 2                 3144                   382          28511              30284
## 3                 3149                   482          32661              33031
## 4                 3131                   470          32187              32548
## 5                 1823                   257           7561               7753
## 6                 2948                   364          24352              25004
##   num_neut_postfilter num_neut_neutralgenome num_causal_temp num_causal_sal
## 1               26587                  12867             310              0
## 2               30284                  14060             382              0
## 3               33031                  16379             480              0
## 4               32548                  16243             469              0
## 5                7753                   3749             257              0
## 6               25004                  12197             364              0
##   num_multiallelic    meanFst va_temp_total va_sal_total Va_temp_sample
## 1                0 0.18039488    0.01185008            0     0.01356519
## 2                0 0.16985797    0.01343736            0     0.01276814
## 3                0 0.13396101    0.01405264            0     0.01370501
## 4                0 0.08714633    0.01337458            0     0.01305077
## 5                0 0.31813358    0.01605415            0     0.01622973
## 6                0 0.12616527    0.01930127            0     0.02072472
##   Va_sal_sample nSNPs median_causal_temp_cor median_causal_sal_cor
## 1             0 26063              0.3580437                    NA
## 2             0 28893              0.4138162                    NA
## 3             0 33143              0.4157033                    NA
## 4             0 32657              0.4112619                    NA
## 5             0  7818              0.3925022                    NA
## 6             0 24716              0.2974287                    NA
##   median_neut_temp_cor median_neut_sal_cor cor_VA_temp_prop cor_VA_sal_prop
## 1            0.3820531          0.04816897        0.8451605               0
## 2            0.4536498          0.04175877        0.7846421               0
## 3            0.4029319          0.03844065        0.7830061               0
## 4            0.3451512          0.04529330        0.7631297               0
## 5            0.4432208          0.05141380        0.8171677               0
## 6            0.2243095          0.19531471        0.6459740               0
##   cor_TPR_temp cor_TPR_sal cor_FDR_allSNPs_temp cor_FDR_neutSNPs_temp
## 1    0.4612903          NA            0.9894449             0.9791241
## 2    0.5314136          NA            0.9886134             0.9769893
## 3    0.5416667          NA            0.9854586             0.9711015
## 4    0.5351812          NA            0.9833466             0.9669693
## 5    0.5408560          NA            0.9711199             0.9447316
## 6    0.3076923          NA            0.9813892             0.9575114
##   cor_FDR_allSNPs_sal cor_FDR_neutSNPs_sal num_causal_sig_temp_corr
## 1                  NA                   NA                      143
## 2                  NA                   NA                      203
## 3                  NA                   NA                      260
## 4                   1                   NA                      251
## 5                  NA                   NA                      139
## 6                   1                    1                      112
##   num_causal_sig_sal_corr num_notCausal_sig_temp_corr
## 1                       0                       13405
## 2                       0                       17625
## 3                       0                       17620
## 4                       0                       14821
## 5                       0                        4674
## 6                       0                        5906
##   num_notCausal_sig_sal_corr num_neut_sig_temp_corr num_neut_sig_sal_corr
## 1                          0                   6707                     0
## 2                          0                   8619                     0
## 3                          0                   8737                     0
## 4                          1                   7348                     0
## 5                          0                   2376                     0
## 6                       4344                   2524                  2133
##   cor_AUCPR_temp_allSNPs cor_AUCPR_temp_neutSNPs cor_AUCPR_sal_allSNPs
## 1             0.01064045              0.02148047                    NA
## 2             0.01053868              0.02130552                    NA
## 3             0.01286086              0.02546132                    NA
## 4             0.01566591              0.03219810                    NA
## 5             0.02696219              0.05312152                    NA
## 6             0.02255358              0.06178401                    NA
##   cor_AUCPR_sal_neutSNPs cor_af_temp_noutliers cor_af_sal_noutliers
## 1                     NA                 13548                    0
## 2                     NA                 17828                    0
## 3                     NA                 17880                    0
## 4                     NA                 15072                    1
## 5                     NA                  4813                    0
## 6                     NA                  6018                 4344
##   cor_FPR_temp_neutSNPs cor_FPR_sal_neutSNPs LEA3.2_lfmm2_Va_temp_prop
## 1             0.5212559            0.0000000                0.27826502
## 2             0.6130156            0.0000000                0.00000000
## 3             0.5334269            0.0000000                0.00000000
## 4             0.4523795            0.0000000                0.00000000
## 5             0.6337690            0.0000000                0.03610723
## 6             0.2069361            0.1748791                0.17163124
##   LEA3.2_lfmm2_Va_sal_prop LEA3.2_lfmm2_TPR_temp LEA3.2_lfmm2_TPR_sal
## 1                       NA           0.022580645                   NA
## 2                       NA           0.000000000                   NA
## 3                       NA           0.000000000                   NA
## 4                       NA           0.000000000                   NA
## 5                       NA           0.003891051                   NA
## 6                       NA           0.005494505                   NA
##   LEA3.2_lfmm2_FDR_allSNPs_temp LEA3.2_lfmm2_FDR_allSNPs_sal
## 1                     0.9789790                           NA
## 2                            NA                            1
## 3                            NA                            1
## 4                     1.0000000                           NA
## 5                     0.9500000                           NA
## 6                     0.8666667                           NA
##   LEA3.2_lfmm2_FDR_neutSNPs_temp LEA3.2_lfmm2_FDR_neutSNPs_sal
## 1                      0.9263158                            NA
## 2                             NA                            NA
## 3                             NA                            NA
## 4                      1.0000000                            NA
## 5                      0.8750000                            NA
## 6                      0.0000000                            NA
##   LEA3.2_lfmm2_AUCPR_temp_allSNPs LEA3.2_lfmm2_AUCPR_temp_neutSNPs
## 1                      0.01339495                       0.02655237
## 2                      0.01367013                       0.02786249
## 3                      0.01426730                       0.02851768
## 4                      0.01310529                       0.02513767
## 5                      0.03463172                       0.06672248
## 6                      0.01437720                       0.02928224
##   LEA3.2_lfmm2_AUCPR_sal_allSNPs LEA3.2_lfmm2_AUCPR_sal_neutSNPs
## 1                             NA                              NA
## 2                             NA                              NA
## 3                             NA                              NA
## 4                             NA                              NA
## 5                             NA                              NA
## 6                             NA                              NA
##   LEA3.2_lfmm2_mlog10P_tempenv_noutliers LEA3.2_lfmm2_mlog10P_salenv_noutliers
## 1                                    333                                     0
## 2                                      0                                     1
## 3                                      0                                     1
## 4                                      6                                     0
## 5                                     20                                     0
## 6                                     15                                     0
##   LEA3.2_lfmm2_num_causal_sig_temp LEA3.2_lfmm2_num_neut_sig_temp
## 1                                7                             88
## 2                                0                              0
## 3                                0                              0
## 4                                0                              2
## 5                                1                              7
## 6                                2                              0
##   LEA3.2_lfmm2_num_causal_sig_sal LEA3.2_lfmm2_num_neut_sig_sal
## 1                               0                             0
## 2                               0                             0
## 3                               0                             0
## 4                               0                             0
## 5                               0                             0
## 6                               0                             0
##   LEA3.2_lfmm2_FPR_neutSNPs_temp LEA3.2_lfmm2_FPR_neutSNPs_sal RDA1_propvar
## 1                    0.006839201                             0        0.985
## 2                    0.000000000                             0        0.989
## 3                    0.000000000                             0        0.988
## 4                    0.000123130                             0        0.980
## 5                    0.001867165                             0        0.991
## 6                    0.000000000                             0        0.596
##   RDA2_propvar RDA1_propvar_corr RDA2_propvar_corr RDA1_temp_cor RDA1_sal_cor
## 1        0.015             0.765             0.235     0.9999982  0.001912722
## 2        0.011             0.835             0.165     0.9999971  0.002425692
## 3        0.012             0.842             0.158     0.9999982  0.001888450
## 4        0.020             0.841             0.159     0.9999700 -0.007739672
## 5        0.009             0.816             0.184     0.9999640  0.008484251
## 6        0.404             0.597             0.403    -0.9360957  0.351745296
##   RDA2_temp_cor RDA2_sal_cor RDA_Va_temp_prop RDA_Va_temp_prop_corr
## 1  -0.001912722    0.9999982        0.1248244           0.000000000
## 2  -0.002425692    0.9999971        0.3566111           0.017427370
## 3  -0.001888450    0.9999982        0.1750594           0.000000000
## 4   0.007739672    0.9999700        0.1339135           0.000000000
## 5  -0.008484251    0.9999640        0.3123098           0.036329553
## 6  -0.351745296   -0.9360957        0.3414487           0.004385126
##   RDA_Va_sal_prop RDA_Va_sal_prop_corr     RDA_TPR RDA_TPR_corr RDA_FDR_allSNPs
## 1               0                    0 0.006451613  0.000000000       0.9918699
## 2               0                    0 0.041884817  0.015706806       0.9953502
## 3               0                    0 0.010373444  0.000000000       0.9957519
## 4               0                    0 0.014893617  0.000000000       0.9941812
## 5               0                    0 0.073929961  0.015564202       0.9850039
## 6               0                    0 0.027472527  0.002747253       0.9889258
##   RDA_FDR_allSNPs_corr num_RDA_sig_causal num_RDA_sig_neutral
## 1            1.0000000                  2                 118
## 2            0.9966979                 16                1545
## 3            1.0000000                  5                 526
## 4            1.0000000                  7                 557
## 5            0.9833333                 19                 583
## 6            0.9979550                 10                 271
##   num_RDA_sig_causal_corr num_RDA_sig_neutral_corr RDA_FDR_neutSNPs
## 1                       0                      200        0.9833333
## 2                       6                      867        0.9897502
## 3                       0                      458        0.9905838
## 4                       0                      577        0.9875887
## 5                       4                      122        0.9684385
## 6                       1                      213        0.9644128
##   RDA_FDR_neutSNPs_corr RDA_AUCPR_allSNPs RDA_AUCPR_neutSNPs
## 1             1.0000000       0.008249728         0.01647883
## 2             0.9931271       0.008916531         0.01857113
## 3             1.0000000       0.009025124         0.01784801
## 4             1.0000000       0.009215389         0.01812750
## 5             0.9682540       0.025358473         0.05094037
## 6             0.9953271       0.014302424         0.02930863
##   RDA_AUCPR_neutSNPs_corr RDA_FPR_neutSNPs RDA_FPR_neutSNPs_corr
## 1              0.01597697      0.009170747            0.01554364
## 2              0.01824752      0.109886202            0.06166430
## 3              0.01820267      0.032114293            0.02796264
## 4              0.01825734      0.034291695            0.03552299
## 5              0.05046366      0.155508136            0.03254201
## 6              0.01982718      0.022218578            0.01746331
##   RDA_RDAmutpred_cor_tempEffect RDA_RDAmutpred_cor_salEffect
## 1                     0.2566239                           NA
## 2                     0.2709340                           NA
## 3                     0.3199777                           NA
## 4                     0.3397117                           NA
## 5                     0.2064143                           NA
## 6                     0.2864279                           NA
##   RDA_absRDAmutpred_cor_tempVa RDA_absRDAmutpred_cor_salVa
## 1                  -0.04251831                          NA
## 2                  -0.06383708                          NA
## 3                  -0.06156140                          NA
## 4                  -0.04360391                          NA
## 5                  -0.05007068                          NA
## 6                  -0.02697188                          NA
##   RDA_RDAmutpred_cor_tempEffect_structcorr
## 1                                0.1711607
## 2                                0.1695575
## 3                                0.2590273
## 4                                0.1412525
## 5                                0.2089774
## 6                                0.1483359
##   RDA_RDAmutpred_cor_salEffect_structcorr
## 1                                      NA
## 2                                      NA
## 3                                      NA
## 4                                      NA
## 5                                      NA
## 6                                      NA
##   RDA_absRDAmutpred_cor_tempVa_structcorr
## 1                             0.002950593
## 2                             0.011548773
## 3                            -0.006744183
## 4                            -0.006811228
## 5                             0.018943112
## 6                             0.011844784
##   RDA_absRDAmutpred_cor_salVa_structcorr RDA_cor_RDA20000temppredict_tempPhen
## 1                                     NA                            0.8530879
## 2                                     NA                            0.8661742
## 3                                     NA                            0.8458619
## 4                                     NA                            0.8566006
## 5                                     NA                            0.8297057
## 6                                     NA                            0.8109670
##   RDA_cor_RDA20000salpredict_salPhen
## 1                                 NA
## 2                                 NA
## 3                                 NA
## 4                                 NA
## 5                                 NA
## 6                                 NA
##   RDA_cor_RDA20000temppredict_tempPhen_structcorr
## 1                                     -0.03541745
## 2                                      0.02470470
## 3                                      0.12927728
## 4                                      0.04149750
## 5                                      0.11539940
## 6                                      0.15610811
##   RDA_cor_RDA20000salpredict_salPhen_structcorr cor_PC1_temp  cor_PC1_sal
## 1                                            NA   -0.9938219 -0.002423473
## 2                                            NA   -0.9763521 -0.002856465
## 3                                            NA   -0.9806495 -0.001193085
## 4                                            NA   -0.9894438  0.006933632
## 5                                            NA   -0.9624753 -0.006417090
## 6                                            NA   -0.9180515  0.333573860
##   cor_PC2_temp  cor_PC2_sal cor_LFMMU1_temp cor_LFMMU1_sal cor_LFMMU2_temp
## 1  -0.02040717 -0.001688470      0.07027960   -0.001851458     -0.23741491
## 2   0.15699463  0.006663054     -0.64036018   -0.002311619      0.16118062
## 3   0.02289691 -0.002251339     -0.05164944   -0.001922661     -0.66955922
## 4  -0.03159957 -0.011695024      0.09041291   -0.007667182     -0.49064055
## 5   0.18621652  0.005399774     -0.64151191   -0.008355460      0.20361826
## 6  -0.33266762 -0.910485583      0.14489884   -0.108366523     -0.05450648
##   cor_LFMMU2_sal cor_PC1_LFMMU1_temp cor_PC1_LFMMU1_sal cor_PC2_LFMMU1_temp
## 1   -0.002823011         -0.09231664          0.9995526           0.9926958
## 2   -0.000199728          0.75497199          0.9963113           0.6504534
## 3   -0.002378429          0.07609171          0.9999081           0.9968609
## 4    0.011008515         -0.12306538         -0.9998272           0.9916547
## 5   -0.005102881          0.79034742          0.9976490           0.5947952
## 6   -0.018196703         -0.47679972         -0.9712646           0.8782899
##   cor_PC2_LFMMU1_sal gwas_TPR_sal gwas_TPR_temp gwas_FDR_sal_neutbase
## 1        0.001339894           NA     0.2290323                    NA
## 2        0.084015793           NA     0.3272251                    NA
## 3        0.004567194           NA     0.3270833                    NA
## 4        0.004580758           NA     0.2430704                    NA
## 5        0.060281782           NA     0.4202335                    NA
## 6       -0.236378957           NA     0.2252747                    NA
##   gwas_FDR_temp_neutbase clinalparadigm_sal_proptop5GWASclines
## 1              0.9667914                                    NA
## 2              0.9696749                                    NA
## 3              0.9616699                                    NA
## 4              0.9497354                                    NA
## 5              0.9174312                                    NA
## 6              0.9382065                                    NA
##   clinalparadigm_temp_proptop5GWASclines clinalparadigm_sal_propsigGWASclines
## 1                              0.6554106                                   NA
## 2                              0.5384083                                   NA
## 3                              0.5530760                                   NA
## 4                              0.5021433                                   NA
## 5                              0.5882353                                   NA
## 6                              0.3446602                                   NA
##   clinalparadigm_temp_propsigGWASclines
## 1                             0.6050302
## 2                             0.5794083
## 3                             0.5593769
## 4                             0.4777563
## 5                             0.6314615
## 6                             0.3099063
tail(out.df)
##         seed n_samp_tot n_samp_per_pop sd_fitness_among_inds
## 2245 1233338       1000             10            0.06989773
## 2246 1233339       1000             10            0.10457515
## 2247 1233340       1000             10            0.10815036
## 2248 1233341       1000             10            0.09447908
## 2249 1233342       1000             10            0.10039771
## 2250 1233343       1000             10            0.11933530
##      sd_fitness_among_pops final_LA K   Bonf_alpha numCausalLowMAFsample
## 2245            0.03432623 0.390202 2 4.302186e-06                     0
## 2246            0.05800045 0.378143 3 2.037324e-06                     0
## 2247            0.05691502 0.386475 3 1.950687e-06                     0
## 2248            0.04351184 0.406991 1 1.582930e-06                     0
## 2249            0.04816428 0.411540 2 1.608648e-06                     0
## 2250            0.06758560 0.361984 1 6.179706e-06                     0
##      all_corr_phen_temp subsamp_corr_phen_temp all_corr_phen_sal
## 2245          0.8105442              0.6442488         0.9331842
## 2246          0.6134233              0.5623938         0.8856847
## 2247          0.6300670              0.5378167         0.9092372
## 2248          0.7915280              0.6228879         0.9145244
## 2249          0.8020544              0.6425425         0.9127410
## 2250          0.8163458              0.6347974         0.8849650
##      subsamp_corr_phen_sal num_causal_prefilter num_causal_postfilter
## 2245             0.8112850                    8                     5
## 2246             0.8061503                   11                     6
## 2247             0.8075816                    8                     6
## 2248             0.8166540                   10                     7
## 2249             0.8128461                   14                     9
## 2250             0.7608153                   12                     8
##      num_non_causal num_neut_prefilter num_neut_postfilter
## 2245          11617              11843               11843
## 2246          24536              25257               25257
## 2247          25626              26975               26975
## 2248          31580              31942               31942
## 2249          31073              31405               31405
## 2250           8083               8197                8197
##      num_neut_neutralgenome num_causal_temp num_causal_sal num_multiallelic
## 2245                   5810               5              5                0
## 2246                  12346               6              6                0
## 2247                  12834               6              6                0
## 2248                  15946               7              7                0
## 2249                  15689               9              9                0
## 2250                   3947               8              8                0
##         meanFst va_temp_total va_sal_total Va_temp_sample Va_sal_sample nSNPs
## 2245 0.14301783    0.14320895   0.06757681     0.13713509    0.06623635 11622
## 2246 0.13350458    0.05299476   0.07273692     0.08494197    0.09831001 24542
## 2247 0.13740776    0.09929097   0.10670097     0.22910565    0.10650756 25632
## 2248 0.08708807    0.13554966   0.10110684     0.13249490    0.10066003 31587
## 2249 0.06704804    0.16714222   0.16315859     0.16734136    0.16310813 31082
## 2250 0.17379409    0.08556485   0.10592398     0.08049695    0.09935857  8091
##      median_causal_temp_cor median_causal_sal_cor median_neut_temp_cor
## 2245              0.2754918             0.5180941            0.2414407
## 2246              0.3026247             0.4175574            0.1850624
## 2247              0.2000535             0.3990216            0.2321665
## 2248              0.2967283             0.4868710            0.2257370
## 2249              0.3428889             0.3406402            0.1621695
## 2250              0.3033895             0.3424647            0.2488890
##      median_neut_sal_cor cor_VA_temp_prop cor_VA_sal_prop cor_TPR_temp
## 2245          0.22546761        0.8516887       0.9978557    0.4000000
## 2246          0.12090175        0.4727327       0.8630538    0.1666667
## 2247          0.10810696        0.7985926       0.7317329    0.1666667
## 2248          0.09267506        0.6560965       0.8820640    0.4285714
## 2249          0.10404740        0.1136390       0.4316080    0.3333333
## 2250          0.13587417        0.3901235       0.8777962    0.3750000
##      cor_TPR_sal cor_FDR_allSNPs_temp cor_FDR_neutSNPs_temp cor_FDR_allSNPs_sal
## 2245   0.8000000            0.9993947             0.9987358           0.9985337
## 2246   0.6666667            0.9997394             0.9995287           0.9949749
## 2247   0.5000000            0.9998285             0.9996431           0.9933775
## 2248   0.8571429            0.9995787             0.9991545           0.9692308
## 2249   0.3333333            0.9989027             0.9976285           0.9916201
## 2250   0.5000000            0.9987903             0.9974958           0.9913043
##      cor_FDR_neutSNPs_sal num_causal_sig_temp_corr num_causal_sig_sal_corr
## 2245            0.9968774                        2                       4
## 2246            0.9840000                        1                       4
## 2247            0.9732143                        1                       3
## 2248            0.8378378                        3                       6
## 2249            0.9700000                        3                       3
## 2250            0.9743590                        3                       4
##      num_notCausal_sig_temp_corr num_notCausal_sig_sal_corr
## 2245                        3302                       2724
## 2246                        3836                        792
## 2247                        5830                        450
## 2248                        7118                        189
## 2249                        2731                        355
## 2250                        2477                        456
##      num_neut_sig_temp_corr num_neut_sig_sal_corr cor_AUCPR_temp_allSNPs
## 2245                   1580                  1277           0.0056220144
## 2246                   2121                   246           0.0007501130
## 2247                   2801                   109           0.0003226524
## 2248                   3545                    31           0.0003352525
## 2249                   1262                    97           0.0050843070
## 2250                   1195                   152           0.0013870159
##      cor_AUCPR_temp_neutSNPs cor_AUCPR_sal_allSNPs cor_AUCPR_sal_neutSNPs
## 2245            0.0161350441            0.09787865              0.4036255
## 2246            0.0013167008            0.24012890              0.3423103
## 2247            0.0006630059            0.17086955              0.1834894
## 2248            0.0006712386            0.40553013              0.7821320
## 2249            0.0109923069            0.11638113              0.1367044
## 2250            0.0029380064            0.02439708              0.2860155
##      cor_af_temp_noutliers cor_af_sal_noutliers cor_FPR_temp_neutSNPs
## 2245                  3304                 2728            0.27194492
## 2246                  3837                  796            0.17179653
## 2247                  5831                  453            0.21824840
## 2248                  7121                  195            0.22231281
## 2249                  2734                  358            0.08043852
## 2250                  2480                  460            0.30276159
##      cor_FPR_sal_neutSNPs LEA3.2_lfmm2_Va_temp_prop LEA3.2_lfmm2_Va_sal_prop
## 2245          0.219793460                 0.0000000                0.9578289
## 2246          0.019925482                 0.4727327                0.9998981
## 2247          0.008493065                 0.0000000                0.9412170
## 2248          0.001944061                 0.0000000                0.8820640
## 2249          0.006182676                 0.0000000                0.9171033
## 2250          0.038510261                 0.0000000                0.8777962
##      LEA3.2_lfmm2_TPR_temp LEA3.2_lfmm2_TPR_sal LEA3.2_lfmm2_FDR_allSNPs_temp
## 2245             0.0000000            0.6000000                            NA
## 2246             0.1666667            0.8333333                             0
## 2247             0.0000000            0.6666667                            NA
## 2248             0.0000000            0.8571429                            NA
## 2249             0.0000000            0.5555556                            NA
## 2250             0.0000000            0.5000000                            NA
##      LEA3.2_lfmm2_FDR_allSNPs_sal LEA3.2_lfmm2_FDR_neutSNPs_temp
## 2245                    0.9302326                             NA
## 2246                    0.9180328                              0
## 2247                    0.9680000                             NA
## 2248                    0.8888889                             NA
## 2249                    0.9253731                             NA
## 2250                    0.9090909                             NA
##      LEA3.2_lfmm2_FDR_neutSNPs_sal LEA3.2_lfmm2_AUCPR_temp_allSNPs
## 2245                           0.0                       0.2881630
## 2246                           0.0                       0.5981415
## 2247                           0.2                       0.2337020
## 2248                           0.0                       0.5925314
## 2249                           0.0                       0.2628556
## 2250                           0.0                       0.2117759
##      LEA3.2_lfmm2_AUCPR_temp_neutSNPs LEA3.2_lfmm2_AUCPR_sal_allSNPs
## 2245                        0.6313777                      0.2881630
## 2246                        0.8340475                      0.5981415
## 2247                        0.7153403                      0.2337020
## 2248                        1.0000000                      0.5925314
## 2249                        0.5658529                      0.2628556
## 2250                        0.5088647                      0.2117759
##      LEA3.2_lfmm2_AUCPR_sal_neutSNPs LEA3.2_lfmm2_mlog10P_tempenv_noutliers
## 2245                       0.6313777                                      0
## 2246                       0.8340475                                      1
## 2247                       0.7153403                                      0
## 2248                       1.0000000                                      0
## 2249                       0.5658529                                      0
## 2250                       0.5088647                                      0
##      LEA3.2_lfmm2_mlog10P_salenv_noutliers LEA3.2_lfmm2_num_causal_sig_temp
## 2245                                    43                                0
## 2246                                    61                                1
## 2247                                   125                                0
## 2248                                    54                                0
## 2249                                    67                                0
## 2250                                    44                                0
##      LEA3.2_lfmm2_num_neut_sig_temp LEA3.2_lfmm2_num_causal_sig_sal
## 2245                              0                               3
## 2246                              0                               5
## 2247                              0                               4
## 2248                              0                               6
## 2249                              0                               5
## 2250                              0                               4
##      LEA3.2_lfmm2_num_neut_sig_sal LEA3.2_lfmm2_FPR_neutSNPs_temp
## 2245                             0                              0
## 2246                             0                              0
## 2247                             1                              0
## 2248                             0                              0
## 2249                             0                              0
## 2250                             0                              0
##      LEA3.2_lfmm2_FPR_neutSNPs_sal RDA1_propvar RDA2_propvar RDA1_propvar_corr
## 2245                  0.000000e+00        0.550        0.450             0.665
## 2246                  0.000000e+00        0.742        0.258             0.558
## 2247                  7.791803e-05        0.716        0.284             0.772
## 2248                  0.000000e+00        0.835        0.165             0.752
## 2249                  0.000000e+00        0.684        0.316             0.624
## 2250                  0.000000e+00        0.739        0.261             0.673
##      RDA2_propvar_corr RDA1_temp_cor RDA1_sal_cor RDA2_temp_cor RDA2_sal_cor
## 2245             0.335     0.5015364 -0.865136554  -0.865136554   -0.5015364
## 2246             0.442     0.9999502 -0.009981000   0.009981000    0.9999502
## 2247             0.228     0.9999683 -0.007965626   0.007965626    0.9999683
## 2248             0.248     0.9991421  0.041413317  -0.041413317    0.9991421
## 2249             0.376     0.9996593  0.026102226  -0.026102226    0.9996593
## 2250             0.327     0.9800515  0.198743495  -0.198743495    0.9800515
##      RDA_Va_temp_prop RDA_Va_temp_prop_corr RDA_Va_sal_prop
## 2245        0.4763587             0.8519800       0.9578289
## 2246        0.9996855             0.9996855       0.9998981
## 2247        0.9995510             0.2009584       0.9742365
## 2248        0.9677581             0.9677581       0.8820640
## 2249        0.9861608             0.9861608       0.9986455
## 2250        0.8073374             0.8955353       0.8777962
##      RDA_Va_sal_prop_corr   RDA_TPR RDA_TPR_corr RDA_FDR_allSNPs
## 2245            0.7328738 0.6000000    0.6000000       0.9931193
## 2246            0.9998981 0.8333333    0.8333333       0.9929478
## 2247            0.9412170 0.8333333    0.6666667       0.9968133
## 2248            0.8820640 0.8571429    0.8571429       0.9963280
## 2249            0.9986455 0.8888889    0.8888889       0.9944328
## 2250            0.9096928 0.5000000    0.6250000       0.9838710
##      RDA_FDR_allSNPs_corr num_RDA_sig_causal num_RDA_sig_neutral
## 2245            0.9934211                  3                 118
## 2246            0.9932249                  5                 230
## 2247            0.9972318                  5                 573
## 2248            0.9955720                  6                 597
## 2249            0.9951190                  8                 479
## 2250            0.9814815                  4                  62
##      num_RDA_sig_causal_corr num_RDA_sig_neutral_corr RDA_FDR_neutSNPs
## 2245                       3                      152        0.9752066
## 2246                       5                      244        0.9787234
## 2247                       4                      523        0.9913495
## 2248                       6                      486        0.9900498
## 2249                       8                      498        0.9835729
## 2250                       5                       92        0.9393939
##      RDA_FDR_neutSNPs_corr RDA_AUCPR_allSNPs RDA_AUCPR_neutSNPs
## 2245             0.9806452         0.1317274          0.6023902
## 2246             0.9799197         0.3896916          0.6725673
## 2247             0.9924099         0.1915153          0.5139129
## 2248             0.9878049         0.3830535          0.8575997
## 2249             0.9841897         0.1615562          0.6298882
## 2250             0.9484536         0.2032180          0.5029961
##      RDA_AUCPR_neutSNPs_corr RDA_FPR_neutSNPs RDA_FPR_neutSNPs_corr
## 2245               0.2991643       0.02030981            0.02616179
## 2246               0.6819382       0.01862952            0.01976349
## 2247               0.5028327       0.04464703            0.04075113
## 2248               0.8575851       0.03743886            0.03047786
## 2249               0.6418724       0.03053095            0.03174198
## 2250               0.3320560       0.01570813            0.02330884
##      RDA_RDAmutpred_cor_tempEffect RDA_RDAmutpred_cor_salEffect
## 2245                     0.6000000                    0.6000000
## 2246                     0.8666667                    0.6000000
## 2247                     0.6000000                    0.6000000
## 2248                     0.5238095                    0.3333333
## 2249                     0.5555556                    0.7777778
## 2250                     0.5000000                    0.2857143
##      RDA_absRDAmutpred_cor_tempVa RDA_absRDAmutpred_cor_salVa
## 2245                  0.020465239                  0.01871735
## 2246                  0.011409116                  0.01826038
## 2247                  0.002784945                  0.01793393
## 2248                  0.017384447                  0.02012018
## 2249                  0.017285637                  0.01862984
## 2250                  0.020696744                  0.02400657
##      RDA_RDAmutpred_cor_tempEffect_structcorr
## 2245                               0.36606915
## 2246                              -0.07001212
## 2247                              -0.07228499
## 2248                               0.15434486
## 2249                               0.12235804
## 2250                               0.27521121
##      RDA_RDAmutpred_cor_salEffect_structcorr
## 2245                               0.9208180
## 2246                               0.8150453
## 2247                               0.8026655
## 2248                               0.7288245
## 2249                               0.7696911
## 2250                               0.6602084
##      RDA_absRDAmutpred_cor_tempVa_structcorr
## 2245                              0.04635961
## 2246                              0.01113341
## 2247                              0.02638952
## 2248                              0.06395474
## 2249                              0.07991070
## 2250                              0.08556552
##      RDA_absRDAmutpred_cor_salVa_structcorr
## 2245                             0.07122715
## 2246                             0.10423641
## 2247                             0.09238268
## 2248                             0.11222190
## 2249                             0.08011436
## 2250                             0.11534351
##      RDA_cor_RDA20000temppredict_tempPhen RDA_cor_RDA20000salpredict_salPhen
## 2245                            0.6025624                          0.6970451
## 2246                            0.5688492                          0.7562831
## 2247                            0.5073146                          0.6932780
## 2248                            0.5917726                          0.7525031
## 2249                            0.6272143                          0.7680113
## 2250                            0.5661217                          0.6653819
##      RDA_cor_RDA20000temppredict_tempPhen_structcorr
## 2245                                      0.02969630
## 2246                                      0.08385813
## 2247                                      0.18613306
## 2248                                      0.05323003
## 2249                                      0.12648538
## 2250                                      0.23854195
##      RDA_cor_RDA20000salpredict_salPhen_structcorr cor_PC1_temp  cor_PC1_sal
## 2245                                     0.2459241  -0.49592948  0.707550286
## 2246                                     0.7608327  -0.03745187  0.010848786
## 2247                                     0.6778338  -0.42331353 -0.036871726
## 2248                                     0.7661762  -0.96800660 -0.035807738
## 2249                                     0.7672155  -0.04223546  0.005524909
## 2250                                     0.6262283   0.78322231  0.099152034
##      cor_PC2_temp cor_PC2_sal cor_LFMMU1_temp cor_LFMMU1_sal cor_LFMMU2_temp
## 2245  -0.79041718 -0.49531715     -0.11538104   -0.196778909      0.41792225
## 2246  -0.93219015  0.01444962     -0.02798592    0.012589562     -0.15180910
## 2247   0.85072814 -0.05730822     -0.07053397   -0.038642435     -0.08318736
## 2248  -0.01224008  0.01880353     -0.01140580   -0.033516495              NA
## 2249   0.95953676  0.03045830     -0.01491703    0.005465646      0.09588969
## 2250  -0.41323121 -0.29453651      0.36840281   -0.066577901              NA
##      cor_LFMMU2_sal cor_PC1_LFMMU1_temp cor_PC1_LFMMU1_sal cor_PC2_LFMMU1_temp
## 2245    -0.59810083          0.90723798         -0.7652270         -0.41739868
## 2246    -0.01327245          0.99957697          0.9980697         -0.01001944
## 2247    -0.04185963          0.92380303          0.9857150          0.37884682
## 2248             NA          0.02513634          0.9995552         -0.99878157
## 2249    -0.01555213          0.99870326         -0.9987481          0.02746745
## 2250             NA          0.80908546         -0.9986383          0.58076635
##      cor_PC2_LFMMU1_sal gwas_TPR_sal gwas_TPR_temp gwas_FDR_sal_neutbase
## 2245      -6.375626e-01    1.0000000     0.8000000             0.9982047
## 2246       5.599139e-02    1.0000000     0.6666667             0.9990089
## 2247       1.607696e-01    1.0000000     0.3333333             0.9990226
## 2248      -6.278494e-05    1.0000000     0.7142857             0.9987023
## 2249       2.751841e-02    0.8888889     1.0000000             0.9985967
## 2250      -2.590842e-02    0.7500000     0.8750000             0.9975440
##      gwas_FDR_temp_neutbase clinalparadigm_sal_proptop5GWASclines
## 2245              0.9944828                             0.3144330
## 2246              0.9959225                             0.4234528
## 2247              0.9990610                             0.3182527
## 2248              0.9943439                             0.1227848
## 2249              0.9601770                             0.2232947
## 2250              0.9964340                             0.5333333
##      clinalparadigm_temp_proptop5GWASclines
## 2245                              0.2817869
## 2246                              0.2060261
## 2247                              0.1224649
## 2248                              0.2430380
## 2249                              0.1273312
## 2250                              0.2074074
##      clinalparadigm_sal_propsigGWASclines clinalparadigm_temp_propsigGWASclines
## 2245                           0.23302128                             0.2378011
## 2246                           0.06177726                             0.1958369
## 2247                           0.03441465                             0.1351293
## 2248                           0.01704694                             0.2437673
## 2249                           0.02904430                             0.1463104
## 2250                           0.09349593                             0.2850657
load("src/0b-final_params-20220428.RData")
sims.df <- final
head(sims.df)
##                                                                     level reps
## 1  highly-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant    1
## 11         highly-polygenic_1-trait__Est-Clines_N-cline-N-to-S_m-constant    1
## 21                  highly-polygenic_1-trait__Est-Clines_N-equal_m_breaks    1
## 31                highly-polygenic_1-trait__Est-Clines_N-equal_m-constant    1
## 41             highly-polygenic_1-trait__Est-Clines_N-variable_m-variable    1
## 51  highly-polygenic_1-trait__SS-Clines_N-cline-center-to-edge_m-constant    1
##                        arch                                   demog_name
## 1  highly-polygenic_1-trait Est-Clines_N-cline-center-to-edge_m-constant
## 11 highly-polygenic_1-trait         Est-Clines_N-cline-N-to-S_m-constant
## 21 highly-polygenic_1-trait                  Est-Clines_N-equal_m_breaks
## 31 highly-polygenic_1-trait                Est-Clines_N-equal_m-constant
## 41 highly-polygenic_1-trait             Est-Clines_N-variable_m-variable
## 51 highly-polygenic_1-trait  SS-Clines_N-cline-center-to-edge_m-constant
##                      demog_level_sub demog_level MIG_x MIG_y xcline ycline
## 1  N-cline-center-to-edge_m-constant  Est-Clines  0.49  0.07 linear linear
## 11         N-cline-N-to-S_m-constant  Est-Clines  0.49  0.07 linear linear
## 21                  N-equal_m_breaks  Est-Clines  0.49  0.07 linear linear
## 31                N-equal_m-constant  Est-Clines  0.49  0.07 linear linear
## 41             N-variable_m-variable  Est-Clines  0.49  0.07 linear linear
## 51 N-cline-center-to-edge_m-constant   SS-Clines  0.03  0.03 linear linear
##      demog METAPOP_SIDE_x METAPOP_SIDE_y Nequal isVariableM MIG_breaks
## 1  Estuary             10             10      4           0          0
## 11 Estuary             10             10      2           0          0
## 21 Estuary             10             10      0           0          1
## 31 Estuary             10             10      0           0          0
## 41 Estuary             10             10      3           1          0
## 51      SS             10             10      4           0          0
##    arch_level_sub       arch_level MU_base MU_QTL_proportion SIGMA_QTN_1
## 1         1-trait highly-polygenic   1e-07              0.25       0.002
## 11        1-trait highly-polygenic   1e-07              0.25       0.002
## 21        1-trait highly-polygenic   1e-07              0.25       0.002
## 31        1-trait highly-polygenic   1e-07              0.25       0.002
## 41        1-trait highly-polygenic   1e-07              0.25       0.002
## 51        1-trait highly-polygenic   1e-07              0.25       0.002
##    SIGMA_QTN_2 SIGMA_K_1 SIGMA_K_2 N_traits ispleiotropy    seed
## 1        0.002       0.5       0.5        1            0 1231094
## 11       0.002       0.5       0.5        1            0 1231095
## 21       0.002       0.5       0.5        1            0 1231096
## 31       0.002       0.5       0.5        1            0 1231097
## 41       0.002       0.5       0.5        1            0 1231098
## 51       0.002       0.5       0.5        1            0 1231099
final.df <- merge(sims.df, out.df, all.x=TRUE)
head(final.df)
##      seed
## 1 1231094
## 2 1231095
## 3 1231096
## 4 1231097
## 5 1231098
## 6 1231099
##                                                                    level reps
## 1 highly-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant    1
## 2         highly-polygenic_1-trait__Est-Clines_N-cline-N-to-S_m-constant    1
## 3                  highly-polygenic_1-trait__Est-Clines_N-equal_m_breaks    1
## 4                highly-polygenic_1-trait__Est-Clines_N-equal_m-constant    1
## 5             highly-polygenic_1-trait__Est-Clines_N-variable_m-variable    1
## 6  highly-polygenic_1-trait__SS-Clines_N-cline-center-to-edge_m-constant    1
##                       arch                                   demog_name
## 1 highly-polygenic_1-trait Est-Clines_N-cline-center-to-edge_m-constant
## 2 highly-polygenic_1-trait         Est-Clines_N-cline-N-to-S_m-constant
## 3 highly-polygenic_1-trait                  Est-Clines_N-equal_m_breaks
## 4 highly-polygenic_1-trait                Est-Clines_N-equal_m-constant
## 5 highly-polygenic_1-trait             Est-Clines_N-variable_m-variable
## 6 highly-polygenic_1-trait  SS-Clines_N-cline-center-to-edge_m-constant
##                     demog_level_sub demog_level MIG_x MIG_y xcline ycline
## 1 N-cline-center-to-edge_m-constant  Est-Clines  0.49  0.07 linear linear
## 2         N-cline-N-to-S_m-constant  Est-Clines  0.49  0.07 linear linear
## 3                  N-equal_m_breaks  Est-Clines  0.49  0.07 linear linear
## 4                N-equal_m-constant  Est-Clines  0.49  0.07 linear linear
## 5             N-variable_m-variable  Est-Clines  0.49  0.07 linear linear
## 6 N-cline-center-to-edge_m-constant   SS-Clines  0.03  0.03 linear linear
##     demog METAPOP_SIDE_x METAPOP_SIDE_y Nequal isVariableM MIG_breaks
## 1 Estuary             10             10      4           0          0
## 2 Estuary             10             10      2           0          0
## 3 Estuary             10             10      0           0          1
## 4 Estuary             10             10      0           0          0
## 5 Estuary             10             10      3           1          0
## 6      SS             10             10      4           0          0
##   arch_level_sub       arch_level MU_base MU_QTL_proportion SIGMA_QTN_1
## 1        1-trait highly-polygenic   1e-07              0.25       0.002
## 2        1-trait highly-polygenic   1e-07              0.25       0.002
## 3        1-trait highly-polygenic   1e-07              0.25       0.002
## 4        1-trait highly-polygenic   1e-07              0.25       0.002
## 5        1-trait highly-polygenic   1e-07              0.25       0.002
## 6        1-trait highly-polygenic   1e-07              0.25       0.002
##   SIGMA_QTN_2 SIGMA_K_1 SIGMA_K_2 N_traits ispleiotropy n_samp_tot
## 1       0.002       0.5       0.5        1            0       1000
## 2       0.002       0.5       0.5        1            0       1000
## 3       0.002       0.5       0.5        1            0       1000
## 4       0.002       0.5       0.5        1            0       1000
## 5       0.002       0.5       0.5        1            0       1000
## 6       0.002       0.5       0.5        1            0       1000
##   n_samp_per_pop sd_fitness_among_inds sd_fitness_among_pops final_LA K
## 1             10            0.05272602            0.01977273 0.500854 2
## 2             10            0.04519923            0.01541145 0.505075 9
## 3             10            0.05348903            0.02022721 0.499265 9
## 4             10            0.05446050            0.01731323 0.499365 9
## 5             10            0.05093029            0.01832588 0.501054 6
## 6             10            0.07552882            0.02341833 0.478131 3
##     Bonf_alpha numCausalLowMAFsample all_corr_phen_temp subsamp_corr_phen_temp
## 1 1.918428e-06                    39          0.9545790              0.8893387
## 2 1.730523e-06                   104          0.9545764              0.9006961
## 3 1.508614e-06                    22          0.9723022              0.8873320
## 4 1.531065e-06                    24          0.9720233              0.8895298
## 5 6.395498e-06                    12          0.9708565              0.8921410
## 6 2.022981e-06                    34          0.9247450              0.8525464
##   all_corr_phen_sal subsamp_corr_phen_sal num_causal_prefilter
## 1                NA                    NA                 2628
## 2                NA                    NA                 3144
## 3                NA                    NA                 3149
## 4                NA                    NA                 3131
## 5                NA                    NA                 1823
## 6                NA                    NA                 2948
##   num_causal_postfilter num_non_causal num_neut_prefilter num_neut_postfilter
## 1                   310          25753              26587               26587
## 2                   382          28511              30284               30284
## 3                   482          32661              33031               33031
## 4                   470          32187              32548               32548
## 5                   257           7561               7753                7753
## 6                   364          24352              25004               25004
##   num_neut_neutralgenome num_causal_temp num_causal_sal num_multiallelic
## 1                  12867             310              0                0
## 2                  14060             382              0                0
## 3                  16379             480              0                0
## 4                  16243             469              0                0
## 5                   3749             257              0                0
## 6                  12197             364              0                0
##      meanFst va_temp_total va_sal_total Va_temp_sample Va_sal_sample nSNPs
## 1 0.18039488    0.01185008            0     0.01356519             0 26063
## 2 0.16985797    0.01343736            0     0.01276814             0 28893
## 3 0.13396101    0.01405264            0     0.01370501             0 33143
## 4 0.08714633    0.01337458            0     0.01305077             0 32657
## 5 0.31813358    0.01605415            0     0.01622973             0  7818
## 6 0.12616527    0.01930127            0     0.02072472             0 24716
##   median_causal_temp_cor median_causal_sal_cor median_neut_temp_cor
## 1              0.3580437                    NA            0.3820531
## 2              0.4138162                    NA            0.4536498
## 3              0.4157033                    NA            0.4029319
## 4              0.4112619                    NA            0.3451512
## 5              0.3925022                    NA            0.4432208
## 6              0.2974287                    NA            0.2243095
##   median_neut_sal_cor cor_VA_temp_prop cor_VA_sal_prop cor_TPR_temp cor_TPR_sal
## 1          0.04816897        0.8451605               0    0.4612903          NA
## 2          0.04175877        0.7846421               0    0.5314136          NA
## 3          0.03844065        0.7830061               0    0.5416667          NA
## 4          0.04529330        0.7631297               0    0.5351812          NA
## 5          0.05141380        0.8171677               0    0.5408560          NA
## 6          0.19531471        0.6459740               0    0.3076923          NA
##   cor_FDR_allSNPs_temp cor_FDR_neutSNPs_temp cor_FDR_allSNPs_sal
## 1            0.9894449             0.9791241                  NA
## 2            0.9886134             0.9769893                  NA
## 3            0.9854586             0.9711015                  NA
## 4            0.9833466             0.9669693                   1
## 5            0.9711199             0.9447316                  NA
## 6            0.9813892             0.9575114                   1
##   cor_FDR_neutSNPs_sal num_causal_sig_temp_corr num_causal_sig_sal_corr
## 1                   NA                      143                       0
## 2                   NA                      203                       0
## 3                   NA                      260                       0
## 4                   NA                      251                       0
## 5                   NA                      139                       0
## 6                    1                      112                       0
##   num_notCausal_sig_temp_corr num_notCausal_sig_sal_corr num_neut_sig_temp_corr
## 1                       13405                          0                   6707
## 2                       17625                          0                   8619
## 3                       17620                          0                   8737
## 4                       14821                          1                   7348
## 5                        4674                          0                   2376
## 6                        5906                       4344                   2524
##   num_neut_sig_sal_corr cor_AUCPR_temp_allSNPs cor_AUCPR_temp_neutSNPs
## 1                     0             0.01064045              0.02148047
## 2                     0             0.01053868              0.02130552
## 3                     0             0.01286086              0.02546132
## 4                     0             0.01566591              0.03219810
## 5                     0             0.02696219              0.05312152
## 6                  2133             0.02255358              0.06178401
##   cor_AUCPR_sal_allSNPs cor_AUCPR_sal_neutSNPs cor_af_temp_noutliers
## 1                    NA                     NA                 13548
## 2                    NA                     NA                 17828
## 3                    NA                     NA                 17880
## 4                    NA                     NA                 15072
## 5                    NA                     NA                  4813
## 6                    NA                     NA                  6018
##   cor_af_sal_noutliers cor_FPR_temp_neutSNPs cor_FPR_sal_neutSNPs
## 1                    0             0.5212559            0.0000000
## 2                    0             0.6130156            0.0000000
## 3                    0             0.5334269            0.0000000
## 4                    1             0.4523795            0.0000000
## 5                    0             0.6337690            0.0000000
## 6                 4344             0.2069361            0.1748791
##   LEA3.2_lfmm2_Va_temp_prop LEA3.2_lfmm2_Va_sal_prop LEA3.2_lfmm2_TPR_temp
## 1                0.27826502                       NA           0.022580645
## 2                0.00000000                       NA           0.000000000
## 3                0.00000000                       NA           0.000000000
## 4                0.00000000                       NA           0.000000000
## 5                0.03610723                       NA           0.003891051
## 6                0.17163124                       NA           0.005494505
##   LEA3.2_lfmm2_TPR_sal LEA3.2_lfmm2_FDR_allSNPs_temp
## 1                   NA                     0.9789790
## 2                   NA                            NA
## 3                   NA                            NA
## 4                   NA                     1.0000000
## 5                   NA                     0.9500000
## 6                   NA                     0.8666667
##   LEA3.2_lfmm2_FDR_allSNPs_sal LEA3.2_lfmm2_FDR_neutSNPs_temp
## 1                           NA                      0.9263158
## 2                            1                             NA
## 3                            1                             NA
## 4                           NA                      1.0000000
## 5                           NA                      0.8750000
## 6                           NA                      0.0000000
##   LEA3.2_lfmm2_FDR_neutSNPs_sal LEA3.2_lfmm2_AUCPR_temp_allSNPs
## 1                            NA                      0.01339495
## 2                            NA                      0.01367013
## 3                            NA                      0.01426730
## 4                            NA                      0.01310529
## 5                            NA                      0.03463172
## 6                            NA                      0.01437720
##   LEA3.2_lfmm2_AUCPR_temp_neutSNPs LEA3.2_lfmm2_AUCPR_sal_allSNPs
## 1                       0.02655237                             NA
## 2                       0.02786249                             NA
## 3                       0.02851768                             NA
## 4                       0.02513767                             NA
## 5                       0.06672248                             NA
## 6                       0.02928224                             NA
##   LEA3.2_lfmm2_AUCPR_sal_neutSNPs LEA3.2_lfmm2_mlog10P_tempenv_noutliers
## 1                              NA                                    333
## 2                              NA                                      0
## 3                              NA                                      0
## 4                              NA                                      6
## 5                              NA                                     20
## 6                              NA                                     15
##   LEA3.2_lfmm2_mlog10P_salenv_noutliers LEA3.2_lfmm2_num_causal_sig_temp
## 1                                     0                                7
## 2                                     1                                0
## 3                                     1                                0
## 4                                     0                                0
## 5                                     0                                1
## 6                                     0                                2
##   LEA3.2_lfmm2_num_neut_sig_temp LEA3.2_lfmm2_num_causal_sig_sal
## 1                             88                               0
## 2                              0                               0
## 3                              0                               0
## 4                              2                               0
## 5                              7                               0
## 6                              0                               0
##   LEA3.2_lfmm2_num_neut_sig_sal LEA3.2_lfmm2_FPR_neutSNPs_temp
## 1                             0                    0.006839201
## 2                             0                    0.000000000
## 3                             0                    0.000000000
## 4                             0                    0.000123130
## 5                             0                    0.001867165
## 6                             0                    0.000000000
##   LEA3.2_lfmm2_FPR_neutSNPs_sal RDA1_propvar RDA2_propvar RDA1_propvar_corr
## 1                             0        0.985        0.015             0.765
## 2                             0        0.989        0.011             0.835
## 3                             0        0.988        0.012             0.842
## 4                             0        0.980        0.020             0.841
## 5                             0        0.991        0.009             0.816
## 6                             0        0.596        0.404             0.597
##   RDA2_propvar_corr RDA1_temp_cor RDA1_sal_cor RDA2_temp_cor RDA2_sal_cor
## 1             0.235     0.9999982  0.001912722  -0.001912722    0.9999982
## 2             0.165     0.9999971  0.002425692  -0.002425692    0.9999971
## 3             0.158     0.9999982  0.001888450  -0.001888450    0.9999982
## 4             0.159     0.9999700 -0.007739672   0.007739672    0.9999700
## 5             0.184     0.9999640  0.008484251  -0.008484251    0.9999640
## 6             0.403    -0.9360957  0.351745296  -0.351745296   -0.9360957
##   RDA_Va_temp_prop RDA_Va_temp_prop_corr RDA_Va_sal_prop RDA_Va_sal_prop_corr
## 1        0.1248244           0.000000000               0                    0
## 2        0.3566111           0.017427370               0                    0
## 3        0.1750594           0.000000000               0                    0
## 4        0.1339135           0.000000000               0                    0
## 5        0.3123098           0.036329553               0                    0
## 6        0.3414487           0.004385126               0                    0
##       RDA_TPR RDA_TPR_corr RDA_FDR_allSNPs RDA_FDR_allSNPs_corr
## 1 0.006451613  0.000000000       0.9918699            1.0000000
## 2 0.041884817  0.015706806       0.9953502            0.9966979
## 3 0.010373444  0.000000000       0.9957519            1.0000000
## 4 0.014893617  0.000000000       0.9941812            1.0000000
## 5 0.073929961  0.015564202       0.9850039            0.9833333
## 6 0.027472527  0.002747253       0.9889258            0.9979550
##   num_RDA_sig_causal num_RDA_sig_neutral num_RDA_sig_causal_corr
## 1                  2                 118                       0
## 2                 16                1545                       6
## 3                  5                 526                       0
## 4                  7                 557                       0
## 5                 19                 583                       4
## 6                 10                 271                       1
##   num_RDA_sig_neutral_corr RDA_FDR_neutSNPs RDA_FDR_neutSNPs_corr
## 1                      200        0.9833333             1.0000000
## 2                      867        0.9897502             0.9931271
## 3                      458        0.9905838             1.0000000
## 4                      577        0.9875887             1.0000000
## 5                      122        0.9684385             0.9682540
## 6                      213        0.9644128             0.9953271
##   RDA_AUCPR_allSNPs RDA_AUCPR_neutSNPs RDA_AUCPR_neutSNPs_corr RDA_FPR_neutSNPs
## 1       0.008249728         0.01647883              0.01597697      0.009170747
## 2       0.008916531         0.01857113              0.01824752      0.109886202
## 3       0.009025124         0.01784801              0.01820267      0.032114293
## 4       0.009215389         0.01812750              0.01825734      0.034291695
## 5       0.025358473         0.05094037              0.05046366      0.155508136
## 6       0.014302424         0.02930863              0.01982718      0.022218578
##   RDA_FPR_neutSNPs_corr RDA_RDAmutpred_cor_tempEffect
## 1            0.01554364                     0.2566239
## 2            0.06166430                     0.2709340
## 3            0.02796264                     0.3199777
## 4            0.03552299                     0.3397117
## 5            0.03254201                     0.2064143
## 6            0.01746331                     0.2864279
##   RDA_RDAmutpred_cor_salEffect RDA_absRDAmutpred_cor_tempVa
## 1                           NA                  -0.04251831
## 2                           NA                  -0.06383708
## 3                           NA                  -0.06156140
## 4                           NA                  -0.04360391
## 5                           NA                  -0.05007068
## 6                           NA                  -0.02697188
##   RDA_absRDAmutpred_cor_salVa RDA_RDAmutpred_cor_tempEffect_structcorr
## 1                          NA                                0.1711607
## 2                          NA                                0.1695575
## 3                          NA                                0.2590273
## 4                          NA                                0.1412525
## 5                          NA                                0.2089774
## 6                          NA                                0.1483359
##   RDA_RDAmutpred_cor_salEffect_structcorr
## 1                                      NA
## 2                                      NA
## 3                                      NA
## 4                                      NA
## 5                                      NA
## 6                                      NA
##   RDA_absRDAmutpred_cor_tempVa_structcorr
## 1                             0.002950593
## 2                             0.011548773
## 3                            -0.006744183
## 4                            -0.006811228
## 5                             0.018943112
## 6                             0.011844784
##   RDA_absRDAmutpred_cor_salVa_structcorr RDA_cor_RDA20000temppredict_tempPhen
## 1                                     NA                            0.8530879
## 2                                     NA                            0.8661742
## 3                                     NA                            0.8458619
## 4                                     NA                            0.8566006
## 5                                     NA                            0.8297057
## 6                                     NA                            0.8109670
##   RDA_cor_RDA20000salpredict_salPhen
## 1                                 NA
## 2                                 NA
## 3                                 NA
## 4                                 NA
## 5                                 NA
## 6                                 NA
##   RDA_cor_RDA20000temppredict_tempPhen_structcorr
## 1                                     -0.03541745
## 2                                      0.02470470
## 3                                      0.12927728
## 4                                      0.04149750
## 5                                      0.11539940
## 6                                      0.15610811
##   RDA_cor_RDA20000salpredict_salPhen_structcorr cor_PC1_temp  cor_PC1_sal
## 1                                            NA   -0.9938219 -0.002423473
## 2                                            NA   -0.9763521 -0.002856465
## 3                                            NA   -0.9806495 -0.001193085
## 4                                            NA   -0.9894438  0.006933632
## 5                                            NA   -0.9624753 -0.006417090
## 6                                            NA   -0.9180515  0.333573860
##   cor_PC2_temp  cor_PC2_sal cor_LFMMU1_temp cor_LFMMU1_sal cor_LFMMU2_temp
## 1  -0.02040717 -0.001688470      0.07027960   -0.001851458     -0.23741491
## 2   0.15699463  0.006663054     -0.64036018   -0.002311619      0.16118062
## 3   0.02289691 -0.002251339     -0.05164944   -0.001922661     -0.66955922
## 4  -0.03159957 -0.011695024      0.09041291   -0.007667182     -0.49064055
## 5   0.18621652  0.005399774     -0.64151191   -0.008355460      0.20361826
## 6  -0.33266762 -0.910485583      0.14489884   -0.108366523     -0.05450648
##   cor_LFMMU2_sal cor_PC1_LFMMU1_temp cor_PC1_LFMMU1_sal cor_PC2_LFMMU1_temp
## 1   -0.002823011         -0.09231664          0.9995526           0.9926958
## 2   -0.000199728          0.75497199          0.9963113           0.6504534
## 3   -0.002378429          0.07609171          0.9999081           0.9968609
## 4    0.011008515         -0.12306538         -0.9998272           0.9916547
## 5   -0.005102881          0.79034742          0.9976490           0.5947952
## 6   -0.018196703         -0.47679972         -0.9712646           0.8782899
##   cor_PC2_LFMMU1_sal gwas_TPR_sal gwas_TPR_temp gwas_FDR_sal_neutbase
## 1        0.001339894           NA     0.2290323                    NA
## 2        0.084015793           NA     0.3272251                    NA
## 3        0.004567194           NA     0.3270833                    NA
## 4        0.004580758           NA     0.2430704                    NA
## 5        0.060281782           NA     0.4202335                    NA
## 6       -0.236378957           NA     0.2252747                    NA
##   gwas_FDR_temp_neutbase clinalparadigm_sal_proptop5GWASclines
## 1              0.9667914                                    NA
## 2              0.9696749                                    NA
## 3              0.9616699                                    NA
## 4              0.9497354                                    NA
## 5              0.9174312                                    NA
## 6              0.9382065                                    NA
##   clinalparadigm_temp_proptop5GWASclines clinalparadigm_sal_propsigGWASclines
## 1                              0.6554106                                   NA
## 2                              0.5384083                                   NA
## 3                              0.5530760                                   NA
## 4                              0.5021433                                   NA
## 5                              0.5882353                                   NA
## 6                              0.3446602                                   NA
##   clinalparadigm_temp_propsigGWASclines
## 1                             0.6050302
## 2                             0.5794083
## 3                             0.5593769
## 4                             0.4777563
## 5                             0.6314615
## 6                             0.3099063
(vars <- t(final.df[1,]))
##                                                 1                                                                       
## seed                                            "1231094"                                                               
## level                                           "highly-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant"
## reps                                            "1"                                                                     
## arch                                            "highly-polygenic_1-trait"                                              
## demog_name                                      "Est-Clines_N-cline-center-to-edge_m-constant"                          
## demog_level_sub                                 "N-cline-center-to-edge_m-constant"                                     
## demog_level                                     "Est-Clines"                                                            
## MIG_x                                           "0.49"                                                                  
## MIG_y                                           "0.07"                                                                  
## xcline                                          "linear"                                                                
## ycline                                          "linear"                                                                
## demog                                           "Estuary"                                                               
## METAPOP_SIDE_x                                  "10"                                                                    
## METAPOP_SIDE_y                                  "10"                                                                    
## Nequal                                          "4"                                                                     
## isVariableM                                     "0"                                                                     
## MIG_breaks                                      "0"                                                                     
## arch_level_sub                                  "1-trait"                                                               
## arch_level                                      "highly-polygenic"                                                      
## MU_base                                         "1e-07"                                                                 
## MU_QTL_proportion                               "0.25"                                                                  
## SIGMA_QTN_1                                     "0.002"                                                                 
## SIGMA_QTN_2                                     "0.002"                                                                 
## SIGMA_K_1                                       "0.5"                                                                   
## SIGMA_K_2                                       "0.5"                                                                   
## N_traits                                        "1"                                                                     
## ispleiotropy                                    "0"                                                                     
## n_samp_tot                                      "1000"                                                                  
## n_samp_per_pop                                  "10"                                                                    
## sd_fitness_among_inds                           "0.05272602"                                                            
## sd_fitness_among_pops                           "0.01977273"                                                            
## final_LA                                        "0.500854"                                                              
## K                                               "2"                                                                     
## Bonf_alpha                                      "1.918428e-06"                                                          
## numCausalLowMAFsample                           "39"                                                                    
## all_corr_phen_temp                              "0.954579"                                                              
## subsamp_corr_phen_temp                          "0.8893387"                                                             
## all_corr_phen_sal                               NA                                                                      
## subsamp_corr_phen_sal                           NA                                                                      
## num_causal_prefilter                            "2628"                                                                  
## num_causal_postfilter                           "310"                                                                   
## num_non_causal                                  "25753"                                                                 
## num_neut_prefilter                              "26587"                                                                 
## num_neut_postfilter                             "26587"                                                                 
## num_neut_neutralgenome                          "12867"                                                                 
## num_causal_temp                                 "310"                                                                   
## num_causal_sal                                  "0"                                                                     
## num_multiallelic                                "0"                                                                     
## meanFst                                         "0.1803949"                                                             
## va_temp_total                                   "0.01185008"                                                            
## va_sal_total                                    "0"                                                                     
## Va_temp_sample                                  "0.01356519"                                                            
## Va_sal_sample                                   "0"                                                                     
## nSNPs                                           "26063"                                                                 
## median_causal_temp_cor                          "0.3580437"                                                             
## median_causal_sal_cor                           NA                                                                      
## median_neut_temp_cor                            "0.3820531"                                                             
## median_neut_sal_cor                             "0.04816897"                                                            
## cor_VA_temp_prop                                "0.8451605"                                                             
## cor_VA_sal_prop                                 "0"                                                                     
## cor_TPR_temp                                    "0.4612903"                                                             
## cor_TPR_sal                                     NA                                                                      
## cor_FDR_allSNPs_temp                            "0.9894449"                                                             
## cor_FDR_neutSNPs_temp                           "0.9791241"                                                             
## cor_FDR_allSNPs_sal                             NA                                                                      
## cor_FDR_neutSNPs_sal                            NA                                                                      
## num_causal_sig_temp_corr                        "143"                                                                   
## num_causal_sig_sal_corr                         "0"                                                                     
## num_notCausal_sig_temp_corr                     "13405"                                                                 
## num_notCausal_sig_sal_corr                      "0"                                                                     
## num_neut_sig_temp_corr                          "6707"                                                                  
## num_neut_sig_sal_corr                           "0"                                                                     
## cor_AUCPR_temp_allSNPs                          "0.01064045"                                                            
## cor_AUCPR_temp_neutSNPs                         "0.02148047"                                                            
## cor_AUCPR_sal_allSNPs                           NA                                                                      
## cor_AUCPR_sal_neutSNPs                          NA                                                                      
## cor_af_temp_noutliers                           "13548"                                                                 
## cor_af_sal_noutliers                            "0"                                                                     
## cor_FPR_temp_neutSNPs                           "0.5212559"                                                             
## cor_FPR_sal_neutSNPs                            "0"                                                                     
## LEA3.2_lfmm2_Va_temp_prop                       "0.278265"                                                              
## LEA3.2_lfmm2_Va_sal_prop                        NA                                                                      
## LEA3.2_lfmm2_TPR_temp                           "0.02258065"                                                            
## LEA3.2_lfmm2_TPR_sal                            NA                                                                      
## LEA3.2_lfmm2_FDR_allSNPs_temp                   "0.978979"                                                              
## LEA3.2_lfmm2_FDR_allSNPs_sal                    NA                                                                      
## LEA3.2_lfmm2_FDR_neutSNPs_temp                  "0.9263158"                                                             
## LEA3.2_lfmm2_FDR_neutSNPs_sal                   NA                                                                      
## LEA3.2_lfmm2_AUCPR_temp_allSNPs                 "0.01339495"                                                            
## LEA3.2_lfmm2_AUCPR_temp_neutSNPs                "0.02655237"                                                            
## LEA3.2_lfmm2_AUCPR_sal_allSNPs                  NA                                                                      
## LEA3.2_lfmm2_AUCPR_sal_neutSNPs                 NA                                                                      
## LEA3.2_lfmm2_mlog10P_tempenv_noutliers          "333"                                                                   
## LEA3.2_lfmm2_mlog10P_salenv_noutliers           "0"                                                                     
## LEA3.2_lfmm2_num_causal_sig_temp                "7"                                                                     
## LEA3.2_lfmm2_num_neut_sig_temp                  "88"                                                                    
## LEA3.2_lfmm2_num_causal_sig_sal                 "0"                                                                     
## LEA3.2_lfmm2_num_neut_sig_sal                   "0"                                                                     
## LEA3.2_lfmm2_FPR_neutSNPs_temp                  "0.006839201"                                                           
## LEA3.2_lfmm2_FPR_neutSNPs_sal                   "0"                                                                     
## RDA1_propvar                                    "0.985"                                                                 
## RDA2_propvar                                    "0.015"                                                                 
## RDA1_propvar_corr                               "0.765"                                                                 
## RDA2_propvar_corr                               "0.235"                                                                 
## RDA1_temp_cor                                   "0.9999982"                                                             
## RDA1_sal_cor                                    "0.001912722"                                                           
## RDA2_temp_cor                                   "-0.001912722"                                                          
## RDA2_sal_cor                                    "0.9999982"                                                             
## RDA_Va_temp_prop                                "0.1248244"                                                             
## RDA_Va_temp_prop_corr                           "0"                                                                     
## RDA_Va_sal_prop                                 "0"                                                                     
## RDA_Va_sal_prop_corr                            "0"                                                                     
## RDA_TPR                                         "0.006451613"                                                           
## RDA_TPR_corr                                    "0"                                                                     
## RDA_FDR_allSNPs                                 "0.9918699"                                                             
## RDA_FDR_allSNPs_corr                            "1"                                                                     
## num_RDA_sig_causal                              "2"                                                                     
## num_RDA_sig_neutral                             "118"                                                                   
## num_RDA_sig_causal_corr                         "0"                                                                     
## num_RDA_sig_neutral_corr                        "200"                                                                   
## RDA_FDR_neutSNPs                                "0.9833333"                                                             
## RDA_FDR_neutSNPs_corr                           "1"                                                                     
## RDA_AUCPR_allSNPs                               "0.008249728"                                                           
## RDA_AUCPR_neutSNPs                              "0.01647883"                                                            
## RDA_AUCPR_neutSNPs_corr                         "0.01597697"                                                            
## RDA_FPR_neutSNPs                                "0.009170747"                                                           
## RDA_FPR_neutSNPs_corr                           "0.01554364"                                                            
## RDA_RDAmutpred_cor_tempEffect                   "0.2566239"                                                             
## RDA_RDAmutpred_cor_salEffect                    NA                                                                      
## RDA_absRDAmutpred_cor_tempVa                    "-0.04251831"                                                           
## RDA_absRDAmutpred_cor_salVa                     NA                                                                      
## RDA_RDAmutpred_cor_tempEffect_structcorr        "0.1711607"                                                             
## RDA_RDAmutpred_cor_salEffect_structcorr         NA                                                                      
## RDA_absRDAmutpred_cor_tempVa_structcorr         "0.002950593"                                                           
## RDA_absRDAmutpred_cor_salVa_structcorr          NA                                                                      
## RDA_cor_RDA20000temppredict_tempPhen            "0.8530879"                                                             
## RDA_cor_RDA20000salpredict_salPhen              NA                                                                      
## RDA_cor_RDA20000temppredict_tempPhen_structcorr "-0.03541745"                                                           
## RDA_cor_RDA20000salpredict_salPhen_structcorr   NA                                                                      
## cor_PC1_temp                                    "-0.9938219"                                                            
## cor_PC1_sal                                     "-0.002423473"                                                          
## cor_PC2_temp                                    "-0.02040717"                                                           
## cor_PC2_sal                                     "-0.00168847"                                                           
## cor_LFMMU1_temp                                 "0.0702796"                                                             
## cor_LFMMU1_sal                                  "-0.001851458"                                                          
## cor_LFMMU2_temp                                 "-0.2374149"                                                            
## cor_LFMMU2_sal                                  "-0.002823011"                                                          
## cor_PC1_LFMMU1_temp                             "-0.09231664"                                                           
## cor_PC1_LFMMU1_sal                              "0.9995526"                                                             
## cor_PC2_LFMMU1_temp                             "0.9926958"                                                             
## cor_PC2_LFMMU1_sal                              "0.001339894"                                                           
## gwas_TPR_sal                                    NA                                                                      
## gwas_TPR_temp                                   "0.2290323"                                                             
## gwas_FDR_sal_neutbase                           NA                                                                      
## gwas_FDR_temp_neutbase                          "0.9667914"                                                             
## clinalparadigm_sal_proptop5GWASclines           NA                                                                      
## clinalparadigm_temp_proptop5GWASclines          "0.6554106"                                                             
## clinalparadigm_sal_propsigGWASclines            NA                                                                      
## clinalparadigm_temp_propsigGWASclines           "0.6050302"
ref <- final.df[,c("seed", "level", "num_causal_postfilter")]

### Make sure 10 reps of each simulation
count <- data.frame(notNA=tapply(final.df$K, final.df$level, 
       function(x){sum(!is.na(x))}
       ))
count
##                                                                                                notNA
## highly-polygenic_1-trait__SS-Mtn_N-equal_m-constant                                               10
## highly-polygenic_1-trait__SS-Mtn_N-variable_m-variable                                            10
## highly-polygenic_1-trait__Est-Clines_N-equal_m_breaks                                             10
## highly-polygenic_1-trait__Est-Clines_N-equal_m-constant                                           10
## highly-polygenic_1-trait__SS-Clines_N-cline-center-to-edge_m-constant                             10
## highly-polygenic_1-trait__SS-Clines_N-equal_m-constant                                            10
## highly-polygenic_1-trait__SS-Mtn_N-cline-center-to-edge_m-constant                                10
## highly-polygenic_1-trait__SS-Clines_N-cline-N-to-S_m-constant                                     10
## highly-polygenic_1-trait__Est-Clines_N-variable_m-variable                                        10
## highly-polygenic_1-trait__SS-Clines_N-equal_m_breaks                                              10
## highly-polygenic_1-trait__SS-Clines_N-variable_m-variable                                         10
## highly-polygenic_1-trait__SS-Mtn_N-equal_m_breaks                                                 10
## highly-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant                            10
## highly-polygenic_1-trait__Est-Clines_N-cline-N-to-S_m-constant                                    10
## highly-polygenic_1-trait__SS-Mtn_N-cline-N-to-S_m-constant                                        10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-cline-N-to-S_m-constant                  10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-cline-center-to-edge_m-constant      10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-equal_m_breaks                        10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-equal_m-constant                      10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-variable_m-variable                  10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-variable_m-variable                   10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-cline-center-to-edge_m-constant       10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-equal_m_breaks                           10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-equal_m_breaks                       10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-equal_m-constant                     10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-variable_m-variable                      10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-cline-N-to-S_m-constant              10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-equal_m-constant                         10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-cline-N-to-S_m-constant               10
## highly-polygenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-cline-center-to-edge_m-constant          10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-cline-center-to-edge_m-constant        10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-equal_m_breaks                      10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-equal_m_breaks                     10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-variable_m-variable                10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-cline-center-to-edge_m-constant    10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-equal_m-constant                    10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-variable_m-variable                 10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable                    10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-cline-N-to-S_m-constant                10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-equal_m-constant                   10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-cline-N-to-S_m-constant             10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-equal_m_breaks                         10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-cline-center-to-edge_m-constant     10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-equal_m-constant                       10
## highly-polygenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-cline-N-to-S_m-constant            10
## highly-polygenic_2-trait-pleiotropy-equal-S__SS-Clines_N-variable_m-variable                      10
## highly-polygenic_2-trait-pleiotropy-equal-S__SS-Clines_N-equal_m_breaks                           10
## highly-polygenic_2-trait-pleiotropy-equal-S__SS-Clines_N-cline-N-to-S_m-constant                  10
## highly-polygenic_2-trait-pleiotropy-equal-S__SS-Clines_N-equal_m-constant                         10
## highly-polygenic_2-trait-pleiotropy-equal-S__Est-Clines_N-equal_m-constant                        10
## highly-polygenic_2-trait-pleiotropy-equal-S__Est-Clines_N-variable_m-variable                     10
## highly-polygenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-equal_m_breaks                              10
## highly-polygenic_2-trait-pleiotropy-equal-S__Est-Clines_N-cline-N-to-S_m-constant                 10
## highly-polygenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-cline-center-to-edge_m-constant             10
## highly-polygenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-cline-N-to-S_m-constant                     10
## highly-polygenic_2-trait-pleiotropy-equal-S__Est-Clines_N-cline-center-to-edge_m-constant         10
## highly-polygenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-equal_m-constant                            10
## highly-polygenic_2-trait-pleiotropy-equal-S__SS-Clines_N-cline-center-to-edge_m-constant          10
## highly-polygenic_2-trait-pleiotropy-equal-S__Est-Clines_N-equal_m_breaks                          10
## highly-polygenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-variable_m-variable                         10
## highly-polygenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-equal_m-constant                          10
## highly-polygenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-equal_m-constant                       10
## highly-polygenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-cline-center-to-edge_m-constant       10
## highly-polygenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-cline-N-to-S_m-constant                10
## highly-polygenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-equal_m-constant                      10
## highly-polygenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-variable_m-variable                    10
## highly-polygenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-equal_m_breaks                         10
## highly-polygenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-cline-N-to-S_m-constant                   10
## highly-polygenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable                       10
## highly-polygenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-variable_m-variable                   10
## highly-polygenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-cline-center-to-edge_m-constant           10
## highly-polygenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-equal_m_breaks                            10
## highly-polygenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-cline-center-to-edge_m-constant        10
## highly-polygenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-cline-N-to-S_m-constant               10
## highly-polygenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-equal_m_breaks                        10
## mod-polygenic_1-trait__SS-Mtn_N-equal_m_breaks                                                    10
## mod-polygenic_1-trait__SS-Mtn_N-variable_m-variable                                               10
## mod-polygenic_1-trait__SS-Mtn_N-equal_m-constant                                                  10
## mod-polygenic_1-trait__SS-Mtn_N-cline-center-to-edge_m-constant                                   10
## mod-polygenic_1-trait__SS-Clines_N-cline-N-to-S_m-constant                                        10
## mod-polygenic_1-trait__Est-Clines_N-cline-N-to-S_m-constant                                       10
## mod-polygenic_1-trait__SS-Clines_N-cline-center-to-edge_m-constant                                10
## mod-polygenic_1-trait__SS-Clines_N-equal_m-constant                                               10
## mod-polygenic_1-trait__Est-Clines_N-equal_m_breaks                                                10
## mod-polygenic_1-trait__SS-Clines_N-equal_m_breaks                                                 10
## mod-polygenic_1-trait__Est-Clines_N-variable_m-variable                                           10
## mod-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant                               10
## mod-polygenic_1-trait__SS-Clines_N-variable_m-variable                                            10
## mod-polygenic_1-trait__SS-Mtn_N-cline-N-to-S_m-constant                                           10
## mod-polygenic_1-trait__Est-Clines_N-equal_m-constant                                              10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-variable_m-variable                      10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-equal_m-constant                         10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-cline-N-to-S_m-constant                  10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-cline-N-to-S_m-constant                     10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-cline-N-to-S_m-constant                 10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-equal_m-constant                        10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-equal_m-constant                            10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-equal_m_breaks                          10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-equal_m_breaks                              10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-cline-center-to-edge_m-constant             10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-cline-center-to-edge_m-constant         10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-cline-center-to-edge_m-constant          10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-variable_m-variable                     10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-variable_m-variable                         10
## mod-polygenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-equal_m_breaks                           10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-cline-N-to-S_m-constant                10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-equal_m_breaks                        10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-equal_m-constant                       10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-cline-center-to-edge_m-constant       10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-cline-center-to-edge_m-constant           10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable                       10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-variable_m-variable                    10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-equal_m-constant                          10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-cline-N-to-S_m-constant                   10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-cline-N-to-S_m-constant               10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-equal_m_breaks                            10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-cline-center-to-edge_m-constant        10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-equal_m-constant                      10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-variable_m-variable                   10
## mod-polygenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-equal_m_breaks                         10
## mod-polygenic_2-trait-pleiotropy-equal-S__SS-Clines_N-equal_m_breaks                              10
## mod-polygenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-equal_m-constant                               10
## mod-polygenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-cline-N-to-S_m-constant                        10
## mod-polygenic_2-trait-pleiotropy-equal-S__Est-Clines_N-equal_m_breaks                             10
## mod-polygenic_2-trait-pleiotropy-equal-S__Est-Clines_N-cline-N-to-S_m-constant                    10
## mod-polygenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-variable_m-variable                            10
## mod-polygenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-cline-center-to-edge_m-constant                10
## mod-polygenic_2-trait-pleiotropy-equal-S__Est-Clines_N-cline-center-to-edge_m-constant            10
## mod-polygenic_2-trait-pleiotropy-equal-S__SS-Clines_N-variable_m-variable                         10
## mod-polygenic_2-trait-pleiotropy-equal-S__Est-Clines_N-equal_m-constant                           10
## mod-polygenic_2-trait-pleiotropy-equal-S__SS-Clines_N-equal_m-constant                            10
## mod-polygenic_2-trait-pleiotropy-equal-S__SS-Clines_N-cline-N-to-S_m-constant                     10
## mod-polygenic_2-trait-pleiotropy-equal-S__SS-Clines_N-cline-center-to-edge_m-constant             10
## mod-polygenic_2-trait-pleiotropy-equal-S__Est-Clines_N-variable_m-variable                        10
## mod-polygenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-equal_m_breaks                                 10
## mod-polygenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-equal_m-constant                          10
## mod-polygenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-cline-center-to-edge_m-constant           10
## mod-polygenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-equal_m_breaks                           10
## mod-polygenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-cline-center-to-edge_m-constant          10
## mod-polygenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-equal_m_breaks                            10
## mod-polygenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-cline-N-to-S_m-constant                      10
## mod-polygenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-equal_m_breaks                               10
## mod-polygenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-cline-center-to-edge_m-constant              10
## mod-polygenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-cline-N-to-S_m-constant                  10
## mod-polygenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-variable_m-variable                      10
## mod-polygenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-variable_m-variable                       10
## mod-polygenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable                          10
## mod-polygenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-equal_m-constant                         10
## mod-polygenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-cline-N-to-S_m-constant                   10
## mod-polygenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-equal_m-constant                             10
## oliogenic_1-trait__SS-Clines_N-equal_m-constant                                                   10
## oliogenic_1-trait__SS-Mtn_N-cline-N-to-S_m-constant                                               10
## oliogenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant                                   10
## oliogenic_1-trait__Est-Clines_N-variable_m-variable                                               10
## oliogenic_1-trait__Est-Clines_N-cline-N-to-S_m-constant                                           10
## oliogenic_1-trait__SS-Mtn_N-cline-center-to-edge_m-constant                                       10
## oliogenic_1-trait__Est-Clines_N-equal_m_breaks                                                    10
## oliogenic_1-trait__Est-Clines_N-equal_m-constant                                                  10
## oliogenic_1-trait__SS-Clines_N-equal_m_breaks                                                     10
## oliogenic_1-trait__SS-Mtn_N-variable_m-variable                                                   10
## oliogenic_1-trait__SS-Mtn_N-equal_m_breaks                                                        10
## oliogenic_1-trait__SS-Clines_N-variable_m-variable                                                10
## oliogenic_1-trait__SS-Clines_N-cline-center-to-edge_m-constant                                    10
## oliogenic_1-trait__SS-Mtn_N-equal_m-constant                                                      10
## oliogenic_1-trait__SS-Clines_N-cline-N-to-S_m-constant                                            10
## oliogenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-cline-N-to-S_m-constant                         10
## oliogenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-cline-N-to-S_m-constant                     10
## oliogenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-cline-center-to-edge_m-constant              10
## oliogenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-variable_m-variable                          10
## oliogenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-cline-center-to-edge_m-constant             10
## oliogenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-cline-N-to-S_m-constant                      10
## oliogenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-equal_m-constant                            10
## oliogenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-cline-center-to-edge_m-constant                 10
## oliogenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-equal_m-constant                                10
## oliogenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-equal_m_breaks                              10
## oliogenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-equal_m_breaks                                  10
## oliogenic_2-trait-no-pleiotropy-equal-S__SS-Mtn_N-variable_m-variable                             10
## oliogenic_2-trait-no-pleiotropy-equal-S__Est-Clines_N-variable_m-variable                         10
## oliogenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-equal_m_breaks                               10
## oliogenic_2-trait-no-pleiotropy-equal-S__SS-Clines_N-equal_m-constant                             10
## oliogenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-cline-center-to-edge_m-constant           10
## oliogenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-equal_m-constant                          10
## oliogenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-equal_m-constant                              10
## oliogenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-equal_m_breaks                             10
## oliogenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-variable_m-variable                       10
## oliogenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-cline-center-to-edge_m-constant            10
## oliogenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-cline-N-to-S_m-constant                   10
## oliogenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-cline-N-to-S_m-constant                       10
## oliogenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-equal_m-constant                           10
## oliogenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable                           10
## oliogenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-cline-N-to-S_m-constant                    10
## oliogenic_2-trait-no-pleiotropy-unequal-S__SS-Clines_N-variable_m-variable                        10
## oliogenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-equal_m_breaks                                10
## oliogenic_2-trait-no-pleiotropy-unequal-S__Est-Clines_N-equal_m_breaks                            10
## oliogenic_2-trait-no-pleiotropy-unequal-S__SS-Mtn_N-cline-center-to-edge_m-constant               10
## oliogenic_2-trait-pleiotropy-equal-S__Est-Clines_N-equal_m-constant                               10
## oliogenic_2-trait-pleiotropy-equal-S__Est-Clines_N-cline-N-to-S_m-constant                        10
## oliogenic_2-trait-pleiotropy-equal-S__SS-Clines_N-cline-center-to-edge_m-constant                 10
## oliogenic_2-trait-pleiotropy-equal-S__SS-Clines_N-equal_m-constant                                10
## oliogenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-equal_m_breaks                                     10
## oliogenic_2-trait-pleiotropy-equal-S__Est-Clines_N-cline-center-to-edge_m-constant                10
## oliogenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-equal_m-constant                                   10
## oliogenic_2-trait-pleiotropy-equal-S__SS-Clines_N-equal_m_breaks                                  10
## oliogenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-cline-center-to-edge_m-constant                    10
## oliogenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-variable_m-variable                                10
## oliogenic_2-trait-pleiotropy-equal-S__SS-Clines_N-cline-N-to-S_m-constant                         10
## oliogenic_2-trait-pleiotropy-equal-S__SS-Clines_N-variable_m-variable                             10
## oliogenic_2-trait-pleiotropy-equal-S__Est-Clines_N-variable_m-variable                            10
## oliogenic_2-trait-pleiotropy-equal-S__Est-Clines_N-equal_m_breaks                                 10
## oliogenic_2-trait-pleiotropy-equal-S__SS-Mtn_N-cline-N-to-S_m-constant                            10
## oliogenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-cline-N-to-S_m-constant                       10
## oliogenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-variable_m-variable                          10
## oliogenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-equal_m-constant                              10
## oliogenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-cline-center-to-edge_m-constant               10
## oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-cline-center-to-edge_m-constant                  10
## oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-equal_m_breaks                                   10
## oliogenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-cline-N-to-S_m-constant                      10
## oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable                              10
## oliogenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-equal_m_breaks                                10
## oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-equal_m-constant                                 10
## oliogenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-equal_m_breaks                               10
## oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-cline-N-to-S_m-constant                          10
## oliogenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-equal_m-constant                             10
## oliogenic_2-trait-pleiotropy-unequal-S__Est-Clines_N-cline-center-to-edge_m-constant              10
## oliogenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-variable_m-variable                           10
### Make sure no NAs in population structure
sum(is.na(final.df$K))
## [1] 0
# Check the levels
levels(final.df$demog_level_sub)
## [1] "N-equal_m-constant"                "N-cline-N-to-S_m-constant"        
## [3] "N-cline-center-to-edge_m-constant" "N-equal_m_breaks"                 
## [5] "N-variable_m-variable"
levels(final.df$arch_level_sub)
## [1] "1-trait"                         "2-trait-no-pleiotropy-equal-S"  
## [3] "2-trait-no-pleiotropy-unequal-S" "2-trait-pleiotropy-equal-S"     
## [5] "2-trait-pleiotropy-unequal-S"

Copy graphs

This optional code is for copying figures for one replicate of each of the 225 levels.

GGtheme for all figures

ggtheme <- theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), panel.border=element_blank(), axis.line = element_line(colour="grey30"), axis.title = element_text(colour="grey20"), axis.text = (element_text(colour="grey30")), legend.title = element_text(colour="grey20"), legend.text = element_text(colour="grey30"))

Color schemes

viridis For SS, SS-Mtn, Estuary mako for demography sub level (m and N) magma for arch_level_sub rocket for arch_level scale_color_viridis(name=“Genic level”, discrete=TRUE, option=“rocket”, begin=0, end=0.9)

Reorder levels

str(final.df$arch_level)
##  Ord.factor w/ 3 levels "highly-polygenic"<..: 1 1 1 1 1 1 1 1 1 1 ...
levels(final.df$arch_level)
## [1] "highly-polygenic" "mod-polygenic"    "oliogenic"
final.df$arch_level <- factor(final.df$arch_level, levels=c( "oliogenic", "mod-polygenic", "highly-polygenic"), ordered=TRUE)

levels(final.df$arch_level) <- c("oligogenic", "mod.\npolygenic", "highly\npolygenic")
str(final.df$arch_level) 
##  Ord.factor w/ 3 levels "oligogenic"<"mod.\npolygenic"<..: 3 3 3 3 3 3 3 3 3 3 ...
levels(final.df$arch_level_sub)
## [1] "1-trait"                         "2-trait-no-pleiotropy-equal-S"  
## [3] "2-trait-no-pleiotropy-unequal-S" "2-trait-pleiotropy-equal-S"     
## [5] "2-trait-pleiotropy-unequal-S"
final.df$ispleiotropy <- factor(final.df$ispleiotropy)
levels(final.df$ispleiotropy) <- c("No pleiotropy", "Pleiotropy")
head(final.df$ispleiotropy)
## [1] No pleiotropy No pleiotropy No pleiotropy No pleiotropy No pleiotropy
## [6] No pleiotropy
## Levels: No pleiotropy Pleiotropy
final.df$arch_level_sub <-
  factor(final.df$arch_level_sub,
  levels=c("1-trait", "2-trait-no-pleiotropy-equal-S",
           "2-trait-pleiotropy-equal-S",
           "2-trait-no-pleiotropy-unequal-S",
           "2-trait-pleiotropy-unequal-S"), ordered=TRUE)

levels(final.df$arch_level_sub) <- c("1 trait", "2 traits, no pleiotropy, equal S",
           "2 traits, pleiotropy, equal S",
           "2 traits, no pleiotropy, unequal S",
           "2 traits, pleiotropy, unequal S")


levels(final.df$arch_level_sub) <- c("1 trait", "2 traits\nno pleiotropy\nequal S",
           "2 traits\npleiotropy\nequal S",
           "2 traits\nno pleiotropy\nunequal S",
           "2 traits\npleiotropy\nunequal S")

final.df$demog_level <- factor(final.df$demog_level, levels=c("SS-Clines", "SS-Mtn", "Est-Clines"), ordered=TRUE)

final.df$demog_level_sub<- factor(final.df$demog_level_sub, levels=c("N-equal_m-constant", "N-equal_m_breaks", "N-cline-N-to-S_m-constant", "N-cline-center-to-edge_m-constant",  "N-variable_m-variable"), ordered=TRUE)

final.df$demog_level_sub <- as.factor(final.df$demog_level_sub)

levels(final.df$demog_level_sub)
## [1] "N-equal_m-constant"                "N-equal_m_breaks"                 
## [3] "N-cline-N-to-S_m-constant"         "N-cline-center-to-edge_m-constant"
## [5] "N-variable_m-variable"
levels(final.df$demog_level_sub) <- c("N equal\nm constant", "N equal\nm breaks", "N latitude cline\nm constant", "N central cline\nm constant",  "N variable\nm variable") #warning, make sure in same order as previous code
levels(final.df$demog_level_sub)
## [1] "N equal\nm constant"          "N equal\nm breaks"           
## [3] "N latitude cline\nm constant" "N central cline\nm constant" 
## [5] "N variable\nm variable"

Plot mean FST

### Check for missing data
sum(is.na(final.df$meanFst))
## [1] 0
summary(final.df$meanFst)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.05211 0.08755 0.13028 0.13349 0.15535 0.49555
sum(is.na(final.df$arch_level_sub))
## [1] 0
sum(is.na(final.df$demog_level))
## [1] 0
nrow(final.df)
## [1] 2250
### Table of mean FST for different levels - no evidence of missing data
tapply(final.df$meanFst, list(final.df$demog_level, final.df$demog_level_sub), mean)
##            N equal\nm constant N equal\nm breaks N latitude cline\nm constant
## SS-Clines           0.05787589        0.08295596                    0.1248306
## SS-Mtn              0.06375824        0.08924858                    0.1331580
## Est-Clines          0.08761539        0.13069710                    0.1582141
##            N central cline\nm constant N variable\nm variable
## SS-Clines                    0.1297529              0.1607639
## SS-Mtn                       0.1388368              0.1676450
## Est-Clines                   0.1872237              0.2897629
tapply(final.df$meanFst, list(final.df$demog_level, final.df$demog_level_sub), length)
##            N equal\nm constant N equal\nm breaks N latitude cline\nm constant
## SS-Clines                  150               150                          150
## SS-Mtn                     150               150                          150
## Est-Clines                 150               150                          150
##            N central cline\nm constant N variable\nm variable
## SS-Clines                          150                    150
## SS-Mtn                             150                    150
## Est-Clines                         150                    150
tapply(final.df$meanFst, list(final.df$demog_level, final.df$arch_level_sub), mean)
##              1 trait 2 traits\nno pleiotropy\nequal S
## SS-Clines  0.1096657                        0.1146675
## SS-Mtn     0.1117598                        0.1237163
## Est-Clines 0.1824936                        0.1767900
##            2 traits\npleiotropy\nequal S 2 traits\nno pleiotropy\nunequal S
## SS-Clines                      0.1135987                          0.1086960
## SS-Mtn                         0.1222853                          0.1185259
## Est-Clines                     0.1682394                          0.1629417
##            2 traits\npleiotropy\nunequal S
## SS-Clines                        0.1095514
## SS-Mtn                           0.1163594
## Est-Clines                       0.1630485
tapply(final.df$meanFst, list(final.df$demog_level, final.df$arch_level_sub), length)
##            1 trait 2 traits\nno pleiotropy\nequal S
## SS-Clines      150                              150
## SS-Mtn         150                              150
## Est-Clines     150                              150
##            2 traits\npleiotropy\nequal S 2 traits\nno pleiotropy\nunequal S
## SS-Clines                            150                                150
## SS-Mtn                               150                                150
## Est-Clines                           150                                150
##            2 traits\npleiotropy\nunequal S
## SS-Clines                              150
## SS-Mtn                                 150
## Est-Clines                             150
### Distribution of FST as a funciton of architecture
f <- ggplot(final.df) + geom_histogram(aes(x=meanFst, fill=arch_level_sub), binwidth=0.01, color="grey") + ggtheme + 
  coord_cartesian(xlim = c(0.0, 0.5)) +   # does not give an error for bins with missing values
  #xlim(0,0.5) + #gives an error for bins with missing values
  facet_grid(demog_level~.) + scale_fill_viridis(option="magma", discrete=TRUE, name="Pleiotropy level") + xlab("Fst") + ylab("Number of simulations")  + theme(legend.position="bottom") +  guides(fill = guide_legend(reverse = TRUE)) + ggtitle("A")
f

pdf(paste0(outputs,"FST_Demog.pdf"), width=8, height=6)
### Distribution of FST as a funciton of demography
  ggplot(final.df) + geom_histogram(aes(x=meanFst, fill=demog_level_sub), binwidth=0.01, color="grey", na.rm=TRUE) + ggtheme + coord_cartesian(xlim = c(0, 0.5), ylim=c(0,160))  + facet_grid(demog_level~., scales="free") + scale_fill_viridis(option="mako", discrete=TRUE, name="Demography level") + xlab("Fst") + ylab("Number of simulations")  + theme(legend.position="bottom") + geom_hline(yintercept=0, color="white", size=1)  + geom_hline(yintercept=0, color="grey10", size=0.1)
  dev.off()
## svg 
##   2
  ggplot(final.df) + geom_histogram(aes(x=meanFst, fill=demog_level_sub, position="stack"), binwidth=0.01, color="grey") + ggtheme + xlim(0,0.5) + facet_grid(demog_level~.) + scale_fill_viridis(option="mako", discrete=TRUE, name="Demography level") + xlab("Fst") + ylab("Number of simulations")  + theme(legend.position="bottom") 
## Warning: Ignoring unknown aesthetics: position
## Warning: Removed 30 rows containing missing values (geom_bar).

ggplot(final.df, aes(x=as.factor(demog_level_sub), y=meanFst, fill=demog_level)) + geom_boxplot(color="grey") + ggtheme + xlab("Demography") + ylab("overall FST")  + ylim(0,0.5) + scale_fill_viridis(discrete=TRUE, name="Landscape")

a<-tapply(final.df$meanFst,final.df$demog_name, mean,  na.rm=TRUE)
b<- tapply(final.df$final_LA,final.df$demog_name, mean,  na.rm=TRUE)
  
cbind(Fst=a,LA=b)
##                                                     Fst        LA
## SS-Clines_N-equal_m-constant                 0.05787589 0.4829661
## SS-Mtn_N-equal_m-constant                    0.06375824 0.4866809
## Est-Clines_N-equal_m-constant                0.08761539 0.4280998
## SS-Clines_N-cline-N-to-S_m-constant          0.12483060 0.4772134
## SS-Mtn_N-cline-N-to-S_m-constant             0.13315802 0.4776251
## Est-Clines_N-cline-N-to-S_m-constant         0.15821409 0.4212553
## SS-Clines_N-cline-center-to-edge_m-constant  0.12975290 0.4762261
## SS-Mtn_N-cline-center-to-edge_m-constant     0.13883682 0.4791905
## Est-Clines_N-cline-center-to-edge_m-constant 0.18722368 0.4203116
## SS-Clines_N-equal_m_breaks                   0.08295596 0.4877002
## SS-Mtn_N-equal_m_breaks                      0.08924858 0.4903118
## Est-Clines_N-equal_m_breaks                  0.13069710 0.4295439
## SS-Clines_N-variable_m-variable              0.16076391 0.4713436
## SS-Mtn_N-variable_m-variable                 0.16764502 0.4669084
## Est-Clines_N-variable_m-variable             0.28976287 0.4251321
ggplot(final.df, aes(x=as.factor(N_traits), y=meanFst, fill=demog_level)) + geom_boxplot(color="grey") + ggtheme + xlab("Number of traits") + ylab("meanFst") + scale_color_viridis(discrete=TRUE) + theme(legend.position = "none") + ylim(0,1) 

Degree local adaptation

Visualize the degree of local adapation

summary(final.df$final_LA)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.2509  0.4033  0.4821  0.4614  0.5201  0.5796
      l1 <- ggplot(final.df) + geom_histogram(aes(x=final_LA, fill=arch_level_sub), binwidth=0.01, color="grey") + ggtheme + coord_cartesian(xlim = c(0, 0.75)) + facet_grid(demog_level~.) + scale_fill_viridis(option="magma", discrete=TRUE, name="Pleiotropy level") + xlab("Amount of local adaptation") + ylab("Number of simulations")  + theme(legend.position="bottom") +
  guides(fill = guide_legend(reverse = TRUE)) + ggtitle("A")  + geom_hline(yintercept=0, color="white", size=1)  + geom_hline(yintercept=0, color="grey10", size=0.1)
l1

ggplot(final.df) + geom_histogram(aes(x=final_LA, fill=demog_level_sub), binwidth=0.01, color="grey") + ggtheme + coord_cartesian(xlim = c(0, 0.6)) + facet_grid(demog_level~.) + scale_fill_viridis(option="mako", discrete=TRUE, name="Demography level") + xlab("Amount of local adaptation") + ylab("Number of simulations")  + theme(legend.position="bottom") +
  guides(fill = guide_legend(reverse = FALSE)) + ggtitle("A")  + geom_hline(yintercept=0, color="white", size=1)  + geom_hline(yintercept=0, color="grey10", size=0.1)

l2<- ggplot(final.df) +
        geom_point(aes(x=subsamp_corr_phen_temp,
                       y=subsamp_corr_phen_sal,
                       color=final_LA,shape=demog_level)) + 
        ggtheme +
      scale_color_viridis(option="mako", name="Local\nAdaptation", begin=0.2, end=1) + coord_cartesian(xlim = c(0.25,1)) + ylim(0.25,1) + xlab("Cor(temp. phenotype, deme temperature)") + ylab("Cor(Env2 phenotype, deme Env2)") + ggtitle("B") +labs(shape="Landscape")  + geom_hline(yintercept=0, color="white", size=1)  + geom_hline(yintercept=0, color="grey10", size=0.1)
  l2
## Warning: Using shapes for an ordinal variable is not advised
## Warning: Removed 450 rows containing missing values (geom_point).
## Warning: Removed 1 rows containing missing values (geom_hline).

## Warning: Removed 1 rows containing missing values (geom_hline).

   # in this case, the removed points have an NA because the "sal" trait was not adaptive in 450 simulations:
  # ggplot(final.df, aes(x=as.factor(N_traits), y=meanFst, fill=demog_level)) + geom_boxplot(color="grey") + ggtheme + xlab("Number of traits") + ylab("meanFst") + scale_color_viridis(discrete=TRUE) + theme(legend.position = "none") + ylim(0,1) + ggtitle("C")
  
  sum(is.na(final.df$subsamp_corr_phen_temp))
## [1] 0
  sum(is.na(final.df$subsamp_corr_phen_sal))
## [1] 450
pdf(paste0(outputs,"AmountLA.pdf"), width=7, height=8)
  grid.arrange(l1,l2, nrow=2)
## Warning: Using shapes for an ordinal variable is not advised
## Warning: Removed 450 rows containing missing values (geom_point).
## Warning: Removed 1 rows containing missing values (geom_hline).

## Warning: Removed 1 rows containing missing values (geom_hline).
dev.off()
## svg 
##   2

Number of loci

# Create a dataframe for plotting
numloc_df <- gather(final.df, key=filter, value=num_loci_causal, num_causal_prefilter, num_causal_postfilter)

numloc_df$filter <- factor(numloc_df$filter, levels = c("num_causal_prefilter", "num_causal_postfilter"), ordered=TRUE)

levels(numloc_df$filter) <- c("Pre MAF filter", "Post filter MAF > 0 .01")
str(numloc_df$filter)
##  Ord.factor w/ 2 levels "Pre MAF filter"<..: 1 1 1 1 1 1 1 1 1 1 ...
tapply( numloc_df$num_loci_causal, list(numloc_df$filter,numloc_df$arch_level), mean, na.rm=TRUE)
##                         oligogenic mod.\npolygenic highly\npolygenic
## Pre MAF filter            12.36267        646.8533          3042.847
## Post filter MAF > 0 .01    7.83600         58.1440           498.948
str(numloc_df$arch_level)
##  Ord.factor w/ 3 levels "oligogenic"<"mod.\npolygenic"<..: 3 3 3 3 3 3 3 3 3 3 ...
# Plot QTN loci
m<- ggplot(numloc_df ) + geom_boxplot(aes(y=num_loci_causal,x = arch_level, fill=filter), color="grey70") + ggtheme + ylim(0,4000) + ylab("Number of causal loci") + xlab("Architecture") + scale_fill_viridis(option="mako", discrete=TRUE)
m

# Check no missing data
sum(is.na(final.df$num_neut_prefilter))
## [1] 0
sum(is.na(final.df$num_neut_postfilter))
## [1] 0
# Plot neutral loci
n <- ggplot(final.df) + geom_violin(aes(y=num_neut_postfilter, x=demog_level_sub, fill=demog_level), color="grey70") + ggtheme + ylab("Number of neutral loci\nafter sampling and MAF filter") + xlab("Demography") + guides(fill=guide_legend(title="Landscape")) + scale_fill_viridis(option="viridis", begin=0, end=1, discrete=TRUE)
n

tapply(final.df$num_neut_postfilter, list(final.df$demog_level_sub), median, na.rm=TRUE)
##          N equal\nm constant            N equal\nm breaks 
##                      31450.0                      31997.0 
## N latitude cline\nm constant  N central cline\nm constant 
##                      27139.5                      25316.0 
##       N variable\nm variable 
##                      10753.5
tapply(final.df$num_neut_postfilter, list(final.df$demog_level_sub), mean, na.rm=TRUE)
##          N equal\nm constant            N equal\nm breaks 
##                     31450.10                     32042.55 
## N latitude cline\nm constant  N central cline\nm constant 
##                     28013.50                     25384.45 
##       N variable\nm variable 
##                     10641.12
pdf(paste0(outputs,"NumLociPrePostfilter.pdf"), width=7, height=8)
  grid.arrange(m, n, nrow=2)
dev.off()
## svg 
##   2

K (Number of populations)

# What determines K?
K_mod <- summary(aov(K~arch + demog_level_sub + demog_level + arch*demog_level_sub*demog_level, data=final.df))
K_mod
##                                    Df Sum Sq Mean Sq  F value   Pr(>F)    
## arch                               14    144      10    3.630 5.36e-06 ***
## demog_level_sub                     4   1458     364  128.881  < 2e-16 ***
## demog_level                         2   6885    3443 1217.544  < 2e-16 ***
## arch:demog_level_sub               56    262       5    1.654  0.00183 ** 
## arch:demog_level                   28    199       7    2.513 2.10e-05 ***
## demog_level_sub:demog_level         8   1972     246   87.177  < 2e-16 ***
## arch:demog_level_sub:demog_level  112    633       6    1.998 8.25e-09 ***
## Residuals                        2025   5726       3                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Percent of variance (SS) explained by each
pervarK <- round(K_mod[[1]][,2]/sum(K_mod[[1]][,2]),2)
data.frame(name=rownames(K_mod[[1]]),pervarK)
##                               name pervarK
## 1 arch                                0.01
## 2 demog_level_sub                     0.08
## 3 demog_level                         0.40
## 4 arch:demog_level_sub                0.02
## 5 arch:demog_level                    0.01
## 6 demog_level_sub:demog_level         0.11
## 7 arch:demog_level_sub:demog_level    0.04
## 8 Residuals                           0.33
  # mostly determined by demography

summary(final.df$K)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   2.000   3.000   4.121   5.000  11.000
pdf(paste0(outputs,"K_by_demog.pdf"), width=6, height=6)
  ggplot(final.df) + geom_histogram(aes(x=K, fill=demog_level), binwidth=1, color="grey") + ggtheme + coord_cartesian(xlim = c(0, 11)) + facet_grid(demog_level_sub~.)  + xlab("Number of population clusters (K)") + ylab("Number of simulations")  + theme(legend.position="bottom") +
  guides(fill = guide_legend(reverse = FALSE))  + geom_hline(yintercept=0, color="white", size=1)  + geom_hline(yintercept=0, color="grey10", size=0.1) + scale_fill_viridis(option="viridis", begin=0, end=1, discrete=TRUE, name="Landscape")
dev.off()
## svg 
##   2

Statistical models

MODELS FOR DIVERGENCE (FST) AND FOR AMOUNT Local adaptation (LA)

levels(final.df$arch)
##  [1] "highly-polygenic_1-trait"                        
##  [2] "highly-polygenic_2-trait-no-pleiotropy-equal-S"  
##  [3] "highly-polygenic_2-trait-no-pleiotropy-unequal-S"
##  [4] "highly-polygenic_2-trait-pleiotropy-equal-S"     
##  [5] "highly-polygenic_2-trait-pleiotropy-unequal-S"   
##  [6] "mod-polygenic_1-trait"                           
##  [7] "mod-polygenic_2-trait-no-pleiotropy-equal-S"     
##  [8] "mod-polygenic_2-trait-no-pleiotropy-unequal-S"   
##  [9] "mod-polygenic_2-trait-pleiotropy-equal-S"        
## [10] "mod-polygenic_2-trait-pleiotropy-unequal-S"      
## [11] "oliogenic_1-trait"                               
## [12] "oliogenic_2-trait-no-pleiotropy-equal-S"         
## [13] "oliogenic_2-trait-no-pleiotropy-unequal-S"       
## [14] "oliogenic_2-trait-pleiotropy-equal-S"            
## [15] "oliogenic_2-trait-pleiotropy-unequal-S"
levels(final.df$demog_level)
## [1] "SS-Clines"  "SS-Mtn"     "Est-Clines"
levels(final.df$demog_level_sub)
## [1] "N equal\nm constant"          "N equal\nm breaks"           
## [3] "N latitude cline\nm constant" "N central cline\nm constant" 
## [5] "N variable\nm variable"
## ANOVA for degree LA
LA_mod <- summary(aov(final_LA~arch + demog_level_sub + demog_level + arch*demog_level_sub*demog_level, data=final.df))
LA_mod
##                                    Df Sum Sq Mean Sq   F value Pr(>F)    
## arch                               14 12.280  0.8771 11593.832 <2e-16 ***
## demog_level_sub                     4  0.065  0.0162   214.755 <2e-16 ***
## demog_level                         2  1.499  0.7495  9907.658 <2e-16 ***
## arch:demog_level_sub               56  0.034  0.0006     7.943 <2e-16 ***
## arch:demog_level                   28  0.862  0.0308   407.106 <2e-16 ***
## demog_level_sub:demog_level         8  0.018  0.0023    30.331 <2e-16 ***
## arch:demog_level_sub:demog_level  112  0.011  0.0001     1.283 0.0272 *  
## Residuals                        2025  0.153  0.0001                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Perent of SS for each explanatory variable
pervarLA <- round(LA_mod[[1]][,2]/sum(LA_mod[[1]][,2]),2)

## ANOVA for FST
FST_mod <- summary(aov(meanFst ~ arch + demog_level_sub + demog_level + arch*demog_level_sub*demog_level, data=final.df))
FST_mod
##                                    Df Sum Sq Mean Sq  F value   Pr(>F)    
## arch                               14  0.035  0.0025    6.982 3.09e-14 ***
## demog_level_sub                     4  4.839  1.2099 3426.501  < 2e-16 ***
## demog_level                         2  1.578  0.7889 2234.390  < 2e-16 ***
## arch:demog_level_sub               56  0.032  0.0006    1.597  0.00353 ** 
## arch:demog_level                   28  0.046  0.0016    4.629 1.82e-14 ***
## demog_level_sub:demog_level         8  0.655  0.0819  231.995  < 2e-16 ***
## arch:demog_level_sub:demog_level  112  0.047  0.0004    1.187  0.09334 .  
## Residuals                        2025  0.715  0.0004                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Perent of SS for each explanatory variable
pervarFST <- round(FST_mod[[1]][,2]/sum(FST_mod[[1]][,2]),2)

data.frame(name=rownames(FST_mod[[1]]),pervarLA, pervarFST)
##                               name pervarLA pervarFST
## 1 arch                                 0.82      0.00
## 2 demog_level_sub                      0.00      0.61
## 3 demog_level                          0.10      0.20
## 4 arch:demog_level_sub                 0.00      0.00
## 5 arch:demog_level                     0.06      0.01
## 6 demog_level_sub:demog_level          0.00      0.08
## 7 arch:demog_level_sub:demog_level     0.00      0.01
## 8 Residuals                            0.01      0.09

MODELS FOR allele frequency (AF) clines

# Create a dataframe for analysis with both traits
stat_df <- gather(final.df, key=trait, value=cor_TPR, cor_TPR_temp, cor_TPR_sal)
tail(stat_df)
##         seed
## 4495 1233338
## 4496 1233339
## 4497 1233340
## 4498 1233341
## 4499 1233342
## 4500 1233343
##                                                                                 level
## 4495          oliogenic_2-trait-pleiotropy-unequal-S__SS-Clines_N-variable_m-variable
## 4496 oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-cline-center-to-edge_m-constant
## 4497         oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-cline-N-to-S_m-constant
## 4498                  oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-equal_m_breaks
## 4499                oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-equal_m-constant
## 4500             oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable
##      reps                                   arch
## 4495   10 oliogenic_2-trait-pleiotropy-unequal-S
## 4496   10 oliogenic_2-trait-pleiotropy-unequal-S
## 4497   10 oliogenic_2-trait-pleiotropy-unequal-S
## 4498   10 oliogenic_2-trait-pleiotropy-unequal-S
## 4499   10 oliogenic_2-trait-pleiotropy-unequal-S
## 4500   10 oliogenic_2-trait-pleiotropy-unequal-S
##                                    demog_name              demog_level_sub
## 4495          SS-Clines_N-variable_m-variable       N variable\nm variable
## 4496 SS-Mtn_N-cline-center-to-edge_m-constant  N central cline\nm constant
## 4497         SS-Mtn_N-cline-N-to-S_m-constant N latitude cline\nm constant
## 4498                  SS-Mtn_N-equal_m_breaks            N equal\nm breaks
## 4499                SS-Mtn_N-equal_m-constant          N equal\nm constant
## 4500             SS-Mtn_N-variable_m-variable       N variable\nm variable
##      demog_level MIG_x MIG_y xcline ycline demog METAPOP_SIDE_x METAPOP_SIDE_y
## 4495   SS-Clines  0.03  0.03 linear linear    SS             10             10
## 4496      SS-Mtn  0.03  0.03      V linear    SS             10             10
## 4497      SS-Mtn  0.03  0.03      V linear    SS             10             10
## 4498      SS-Mtn  0.03  0.03      V linear    SS             10             10
## 4499      SS-Mtn  0.03  0.03      V linear    SS             10             10
## 4500      SS-Mtn  0.03  0.03      V linear    SS             10             10
##      Nequal isVariableM MIG_breaks                  arch_level_sub arch_level
## 4495      3           1          0 2 traits\npleiotropy\nunequal S oligogenic
## 4496      4           0          0 2 traits\npleiotropy\nunequal S oligogenic
## 4497      2           0          0 2 traits\npleiotropy\nunequal S oligogenic
## 4498      0           0          1 2 traits\npleiotropy\nunequal S oligogenic
## 4499      0           0          0 2 traits\npleiotropy\nunequal S oligogenic
## 4500      3           1          0 2 traits\npleiotropy\nunequal S oligogenic
##      MU_base MU_QTL_proportion SIGMA_QTN_1 SIGMA_QTN_2 SIGMA_K_1 SIGMA_K_2
## 4495   1e-07             0.001         0.4         0.4       0.5         4
## 4496   1e-07             0.001         0.4         0.4       0.5         4
## 4497   1e-07             0.001         0.4         0.4       0.5         4
## 4498   1e-07             0.001         0.4         0.4       0.5         4
## 4499   1e-07             0.001         0.4         0.4       0.5         4
## 4500   1e-07             0.001         0.4         0.4       0.5         4
##      N_traits ispleiotropy n_samp_tot n_samp_per_pop sd_fitness_among_inds
## 4495        2   Pleiotropy       1000             10            0.06989773
## 4496        2   Pleiotropy       1000             10            0.10457515
## 4497        2   Pleiotropy       1000             10            0.10815036
## 4498        2   Pleiotropy       1000             10            0.09447908
## 4499        2   Pleiotropy       1000             10            0.10039771
## 4500        2   Pleiotropy       1000             10            0.11933530
##      sd_fitness_among_pops final_LA K   Bonf_alpha numCausalLowMAFsample
## 4495            0.03432623 0.390202 2 4.302186e-06                     0
## 4496            0.05800045 0.378143 3 2.037324e-06                     0
## 4497            0.05691502 0.386475 3 1.950687e-06                     0
## 4498            0.04351184 0.406991 1 1.582930e-06                     0
## 4499            0.04816428 0.411540 2 1.608648e-06                     0
## 4500            0.06758560 0.361984 1 6.179706e-06                     0
##      all_corr_phen_temp subsamp_corr_phen_temp all_corr_phen_sal
## 4495          0.8105442              0.6442488         0.9331842
## 4496          0.6134233              0.5623938         0.8856847
## 4497          0.6300670              0.5378167         0.9092372
## 4498          0.7915280              0.6228879         0.9145244
## 4499          0.8020544              0.6425425         0.9127410
## 4500          0.8163458              0.6347974         0.8849650
##      subsamp_corr_phen_sal num_causal_prefilter num_causal_postfilter
## 4495             0.8112850                    8                     5
## 4496             0.8061503                   11                     6
## 4497             0.8075816                    8                     6
## 4498             0.8166540                   10                     7
## 4499             0.8128461                   14                     9
## 4500             0.7608153                   12                     8
##      num_non_causal num_neut_prefilter num_neut_postfilter
## 4495          11617              11843               11843
## 4496          24536              25257               25257
## 4497          25626              26975               26975
## 4498          31580              31942               31942
## 4499          31073              31405               31405
## 4500           8083               8197                8197
##      num_neut_neutralgenome num_causal_temp num_causal_sal num_multiallelic
## 4495                   5810               5              5                0
## 4496                  12346               6              6                0
## 4497                  12834               6              6                0
## 4498                  15946               7              7                0
## 4499                  15689               9              9                0
## 4500                   3947               8              8                0
##         meanFst va_temp_total va_sal_total Va_temp_sample Va_sal_sample nSNPs
## 4495 0.14301783    0.14320895   0.06757681     0.13713509    0.06623635 11622
## 4496 0.13350458    0.05299476   0.07273692     0.08494197    0.09831001 24542
## 4497 0.13740776    0.09929097   0.10670097     0.22910565    0.10650756 25632
## 4498 0.08708807    0.13554966   0.10110684     0.13249490    0.10066003 31587
## 4499 0.06704804    0.16714222   0.16315859     0.16734136    0.16310813 31082
## 4500 0.17379409    0.08556485   0.10592398     0.08049695    0.09935857  8091
##      median_causal_temp_cor median_causal_sal_cor median_neut_temp_cor
## 4495              0.2754918             0.5180941            0.2414407
## 4496              0.3026247             0.4175574            0.1850624
## 4497              0.2000535             0.3990216            0.2321665
## 4498              0.2967283             0.4868710            0.2257370
## 4499              0.3428889             0.3406402            0.1621695
## 4500              0.3033895             0.3424647            0.2488890
##      median_neut_sal_cor cor_VA_temp_prop cor_VA_sal_prop cor_FDR_allSNPs_temp
## 4495          0.22546761        0.8516887       0.9978557            0.9993947
## 4496          0.12090175        0.4727327       0.8630538            0.9997394
## 4497          0.10810696        0.7985926       0.7317329            0.9998285
## 4498          0.09267506        0.6560965       0.8820640            0.9995787
## 4499          0.10404740        0.1136390       0.4316080            0.9989027
## 4500          0.13587417        0.3901235       0.8777962            0.9987903
##      cor_FDR_neutSNPs_temp cor_FDR_allSNPs_sal cor_FDR_neutSNPs_sal
## 4495             0.9987358           0.9985337            0.9968774
## 4496             0.9995287           0.9949749            0.9840000
## 4497             0.9996431           0.9933775            0.9732143
## 4498             0.9991545           0.9692308            0.8378378
## 4499             0.9976285           0.9916201            0.9700000
## 4500             0.9974958           0.9913043            0.9743590
##      num_causal_sig_temp_corr num_causal_sig_sal_corr
## 4495                        2                       4
## 4496                        1                       4
## 4497                        1                       3
## 4498                        3                       6
## 4499                        3                       3
## 4500                        3                       4
##      num_notCausal_sig_temp_corr num_notCausal_sig_sal_corr
## 4495                        3302                       2724
## 4496                        3836                        792
## 4497                        5830                        450
## 4498                        7118                        189
## 4499                        2731                        355
## 4500                        2477                        456
##      num_neut_sig_temp_corr num_neut_sig_sal_corr cor_AUCPR_temp_allSNPs
## 4495                   1580                  1277           0.0056220144
## 4496                   2121                   246           0.0007501130
## 4497                   2801                   109           0.0003226524
## 4498                   3545                    31           0.0003352525
## 4499                   1262                    97           0.0050843070
## 4500                   1195                   152           0.0013870159
##      cor_AUCPR_temp_neutSNPs cor_AUCPR_sal_allSNPs cor_AUCPR_sal_neutSNPs
## 4495            0.0161350441            0.09787865              0.4036255
## 4496            0.0013167008            0.24012890              0.3423103
## 4497            0.0006630059            0.17086955              0.1834894
## 4498            0.0006712386            0.40553013              0.7821320
## 4499            0.0109923069            0.11638113              0.1367044
## 4500            0.0029380064            0.02439708              0.2860155
##      cor_af_temp_noutliers cor_af_sal_noutliers cor_FPR_temp_neutSNPs
## 4495                  3304                 2728            0.27194492
## 4496                  3837                  796            0.17179653
## 4497                  5831                  453            0.21824840
## 4498                  7121                  195            0.22231281
## 4499                  2734                  358            0.08043852
## 4500                  2480                  460            0.30276159
##      cor_FPR_sal_neutSNPs LEA3.2_lfmm2_Va_temp_prop LEA3.2_lfmm2_Va_sal_prop
## 4495          0.219793460                 0.0000000                0.9578289
## 4496          0.019925482                 0.4727327                0.9998981
## 4497          0.008493065                 0.0000000                0.9412170
## 4498          0.001944061                 0.0000000                0.8820640
## 4499          0.006182676                 0.0000000                0.9171033
## 4500          0.038510261                 0.0000000                0.8777962
##      LEA3.2_lfmm2_TPR_temp LEA3.2_lfmm2_TPR_sal LEA3.2_lfmm2_FDR_allSNPs_temp
## 4495             0.0000000            0.6000000                            NA
## 4496             0.1666667            0.8333333                             0
## 4497             0.0000000            0.6666667                            NA
## 4498             0.0000000            0.8571429                            NA
## 4499             0.0000000            0.5555556                            NA
## 4500             0.0000000            0.5000000                            NA
##      LEA3.2_lfmm2_FDR_allSNPs_sal LEA3.2_lfmm2_FDR_neutSNPs_temp
## 4495                    0.9302326                             NA
## 4496                    0.9180328                              0
## 4497                    0.9680000                             NA
## 4498                    0.8888889                             NA
## 4499                    0.9253731                             NA
## 4500                    0.9090909                             NA
##      LEA3.2_lfmm2_FDR_neutSNPs_sal LEA3.2_lfmm2_AUCPR_temp_allSNPs
## 4495                           0.0                       0.2881630
## 4496                           0.0                       0.5981415
## 4497                           0.2                       0.2337020
## 4498                           0.0                       0.5925314
## 4499                           0.0                       0.2628556
## 4500                           0.0                       0.2117759
##      LEA3.2_lfmm2_AUCPR_temp_neutSNPs LEA3.2_lfmm2_AUCPR_sal_allSNPs
## 4495                        0.6313777                      0.2881630
## 4496                        0.8340475                      0.5981415
## 4497                        0.7153403                      0.2337020
## 4498                        1.0000000                      0.5925314
## 4499                        0.5658529                      0.2628556
## 4500                        0.5088647                      0.2117759
##      LEA3.2_lfmm2_AUCPR_sal_neutSNPs LEA3.2_lfmm2_mlog10P_tempenv_noutliers
## 4495                       0.6313777                                      0
## 4496                       0.8340475                                      1
## 4497                       0.7153403                                      0
## 4498                       1.0000000                                      0
## 4499                       0.5658529                                      0
## 4500                       0.5088647                                      0
##      LEA3.2_lfmm2_mlog10P_salenv_noutliers LEA3.2_lfmm2_num_causal_sig_temp
## 4495                                    43                                0
## 4496                                    61                                1
## 4497                                   125                                0
## 4498                                    54                                0
## 4499                                    67                                0
## 4500                                    44                                0
##      LEA3.2_lfmm2_num_neut_sig_temp LEA3.2_lfmm2_num_causal_sig_sal
## 4495                              0                               3
## 4496                              0                               5
## 4497                              0                               4
## 4498                              0                               6
## 4499                              0                               5
## 4500                              0                               4
##      LEA3.2_lfmm2_num_neut_sig_sal LEA3.2_lfmm2_FPR_neutSNPs_temp
## 4495                             0                              0
## 4496                             0                              0
## 4497                             1                              0
## 4498                             0                              0
## 4499                             0                              0
## 4500                             0                              0
##      LEA3.2_lfmm2_FPR_neutSNPs_sal RDA1_propvar RDA2_propvar RDA1_propvar_corr
## 4495                  0.000000e+00        0.550        0.450             0.665
## 4496                  0.000000e+00        0.742        0.258             0.558
## 4497                  7.791803e-05        0.716        0.284             0.772
## 4498                  0.000000e+00        0.835        0.165             0.752
## 4499                  0.000000e+00        0.684        0.316             0.624
## 4500                  0.000000e+00        0.739        0.261             0.673
##      RDA2_propvar_corr RDA1_temp_cor RDA1_sal_cor RDA2_temp_cor RDA2_sal_cor
## 4495             0.335     0.5015364 -0.865136554  -0.865136554   -0.5015364
## 4496             0.442     0.9999502 -0.009981000   0.009981000    0.9999502
## 4497             0.228     0.9999683 -0.007965626   0.007965626    0.9999683
## 4498             0.248     0.9991421  0.041413317  -0.041413317    0.9991421
## 4499             0.376     0.9996593  0.026102226  -0.026102226    0.9996593
## 4500             0.327     0.9800515  0.198743495  -0.198743495    0.9800515
##      RDA_Va_temp_prop RDA_Va_temp_prop_corr RDA_Va_sal_prop
## 4495        0.4763587             0.8519800       0.9578289
## 4496        0.9996855             0.9996855       0.9998981
## 4497        0.9995510             0.2009584       0.9742365
## 4498        0.9677581             0.9677581       0.8820640
## 4499        0.9861608             0.9861608       0.9986455
## 4500        0.8073374             0.8955353       0.8777962
##      RDA_Va_sal_prop_corr   RDA_TPR RDA_TPR_corr RDA_FDR_allSNPs
## 4495            0.7328738 0.6000000    0.6000000       0.9931193
## 4496            0.9998981 0.8333333    0.8333333       0.9929478
## 4497            0.9412170 0.8333333    0.6666667       0.9968133
## 4498            0.8820640 0.8571429    0.8571429       0.9963280
## 4499            0.9986455 0.8888889    0.8888889       0.9944328
## 4500            0.9096928 0.5000000    0.6250000       0.9838710
##      RDA_FDR_allSNPs_corr num_RDA_sig_causal num_RDA_sig_neutral
## 4495            0.9934211                  3                 118
## 4496            0.9932249                  5                 230
## 4497            0.9972318                  5                 573
## 4498            0.9955720                  6                 597
## 4499            0.9951190                  8                 479
## 4500            0.9814815                  4                  62
##      num_RDA_sig_causal_corr num_RDA_sig_neutral_corr RDA_FDR_neutSNPs
## 4495                       3                      152        0.9752066
## 4496                       5                      244        0.9787234
## 4497                       4                      523        0.9913495
## 4498                       6                      486        0.9900498
## 4499                       8                      498        0.9835729
## 4500                       5                       92        0.9393939
##      RDA_FDR_neutSNPs_corr RDA_AUCPR_allSNPs RDA_AUCPR_neutSNPs
## 4495             0.9806452         0.1317274          0.6023902
## 4496             0.9799197         0.3896916          0.6725673
## 4497             0.9924099         0.1915153          0.5139129
## 4498             0.9878049         0.3830535          0.8575997
## 4499             0.9841897         0.1615562          0.6298882
## 4500             0.9484536         0.2032180          0.5029961
##      RDA_AUCPR_neutSNPs_corr RDA_FPR_neutSNPs RDA_FPR_neutSNPs_corr
## 4495               0.2991643       0.02030981            0.02616179
## 4496               0.6819382       0.01862952            0.01976349
## 4497               0.5028327       0.04464703            0.04075113
## 4498               0.8575851       0.03743886            0.03047786
## 4499               0.6418724       0.03053095            0.03174198
## 4500               0.3320560       0.01570813            0.02330884
##      RDA_RDAmutpred_cor_tempEffect RDA_RDAmutpred_cor_salEffect
## 4495                     0.6000000                    0.6000000
## 4496                     0.8666667                    0.6000000
## 4497                     0.6000000                    0.6000000
## 4498                     0.5238095                    0.3333333
## 4499                     0.5555556                    0.7777778
## 4500                     0.5000000                    0.2857143
##      RDA_absRDAmutpred_cor_tempVa RDA_absRDAmutpred_cor_salVa
## 4495                  0.020465239                  0.01871735
## 4496                  0.011409116                  0.01826038
## 4497                  0.002784945                  0.01793393
## 4498                  0.017384447                  0.02012018
## 4499                  0.017285637                  0.01862984
## 4500                  0.020696744                  0.02400657
##      RDA_RDAmutpred_cor_tempEffect_structcorr
## 4495                               0.36606915
## 4496                              -0.07001212
## 4497                              -0.07228499
## 4498                               0.15434486
## 4499                               0.12235804
## 4500                               0.27521121
##      RDA_RDAmutpred_cor_salEffect_structcorr
## 4495                               0.9208180
## 4496                               0.8150453
## 4497                               0.8026655
## 4498                               0.7288245
## 4499                               0.7696911
## 4500                               0.6602084
##      RDA_absRDAmutpred_cor_tempVa_structcorr
## 4495                              0.04635961
## 4496                              0.01113341
## 4497                              0.02638952
## 4498                              0.06395474
## 4499                              0.07991070
## 4500                              0.08556552
##      RDA_absRDAmutpred_cor_salVa_structcorr
## 4495                             0.07122715
## 4496                             0.10423641
## 4497                             0.09238268
## 4498                             0.11222190
## 4499                             0.08011436
## 4500                             0.11534351
##      RDA_cor_RDA20000temppredict_tempPhen RDA_cor_RDA20000salpredict_salPhen
## 4495                            0.6025624                          0.6970451
## 4496                            0.5688492                          0.7562831
## 4497                            0.5073146                          0.6932780
## 4498                            0.5917726                          0.7525031
## 4499                            0.6272143                          0.7680113
## 4500                            0.5661217                          0.6653819
##      RDA_cor_RDA20000temppredict_tempPhen_structcorr
## 4495                                      0.02969630
## 4496                                      0.08385813
## 4497                                      0.18613306
## 4498                                      0.05323003
## 4499                                      0.12648538
## 4500                                      0.23854195
##      RDA_cor_RDA20000salpredict_salPhen_structcorr cor_PC1_temp  cor_PC1_sal
## 4495                                     0.2459241  -0.49592948  0.707550286
## 4496                                     0.7608327  -0.03745187  0.010848786
## 4497                                     0.6778338  -0.42331353 -0.036871726
## 4498                                     0.7661762  -0.96800660 -0.035807738
## 4499                                     0.7672155  -0.04223546  0.005524909
## 4500                                     0.6262283   0.78322231  0.099152034
##      cor_PC2_temp cor_PC2_sal cor_LFMMU1_temp cor_LFMMU1_sal cor_LFMMU2_temp
## 4495  -0.79041718 -0.49531715     -0.11538104   -0.196778909      0.41792225
## 4496  -0.93219015  0.01444962     -0.02798592    0.012589562     -0.15180910
## 4497   0.85072814 -0.05730822     -0.07053397   -0.038642435     -0.08318736
## 4498  -0.01224008  0.01880353     -0.01140580   -0.033516495              NA
## 4499   0.95953676  0.03045830     -0.01491703    0.005465646      0.09588969
## 4500  -0.41323121 -0.29453651      0.36840281   -0.066577901              NA
##      cor_LFMMU2_sal cor_PC1_LFMMU1_temp cor_PC1_LFMMU1_sal cor_PC2_LFMMU1_temp
## 4495    -0.59810083          0.90723798         -0.7652270         -0.41739868
## 4496    -0.01327245          0.99957697          0.9980697         -0.01001944
## 4497    -0.04185963          0.92380303          0.9857150          0.37884682
## 4498             NA          0.02513634          0.9995552         -0.99878157
## 4499    -0.01555213          0.99870326         -0.9987481          0.02746745
## 4500             NA          0.80908546         -0.9986383          0.58076635
##      cor_PC2_LFMMU1_sal gwas_TPR_sal gwas_TPR_temp gwas_FDR_sal_neutbase
## 4495      -6.375626e-01    1.0000000     0.8000000             0.9982047
## 4496       5.599139e-02    1.0000000     0.6666667             0.9990089
## 4497       1.607696e-01    1.0000000     0.3333333             0.9990226
## 4498      -6.278494e-05    1.0000000     0.7142857             0.9987023
## 4499       2.751841e-02    0.8888889     1.0000000             0.9985967
## 4500      -2.590842e-02    0.7500000     0.8750000             0.9975440
##      gwas_FDR_temp_neutbase clinalparadigm_sal_proptop5GWASclines
## 4495              0.9944828                             0.3144330
## 4496              0.9959225                             0.4234528
## 4497              0.9990610                             0.3182527
## 4498              0.9943439                             0.1227848
## 4499              0.9601770                             0.2232947
## 4500              0.9964340                             0.5333333
##      clinalparadigm_temp_proptop5GWASclines
## 4495                              0.2817869
## 4496                              0.2060261
## 4497                              0.1224649
## 4498                              0.2430380
## 4499                              0.1273312
## 4500                              0.2074074
##      clinalparadigm_sal_propsigGWASclines clinalparadigm_temp_propsigGWASclines
## 4495                           0.23302128                             0.2378011
## 4496                           0.06177726                             0.1958369
## 4497                           0.03441465                             0.1351293
## 4498                           0.01704694                             0.2437673
## 4499                           0.02904430                             0.1463104
## 4500                           0.09349593                             0.2850657
##            trait   cor_TPR
## 4495 cor_TPR_sal 0.8000000
## 4496 cor_TPR_sal 0.6666667
## 4497 cor_TPR_sal 0.5000000
## 4498 cor_TPR_sal 0.8571429
## 4499 cor_TPR_sal 0.3333333
## 4500 cor_TPR_sal 0.5000000
# Check the levels in the new dataframe
unique(stat_df$demog_level)
## [1] Est-Clines SS-Clines  SS-Mtn    
## Levels: SS-Clines < SS-Mtn < Est-Clines
unique(stat_df$demog_level_sub)
## [1] N central cline\nm constant  N latitude cline\nm constant
## [3] N equal\nm breaks            N equal\nm constant         
## [5] N variable\nm variable      
## 5 Levels: N equal\nm constant < ... < N variable\nm variable
unique(stat_df$demog_name)
##  [1] Est-Clines_N-cline-center-to-edge_m-constant
##  [2] Est-Clines_N-cline-N-to-S_m-constant        
##  [3] Est-Clines_N-equal_m_breaks                 
##  [4] Est-Clines_N-equal_m-constant               
##  [5] Est-Clines_N-variable_m-variable            
##  [6] SS-Clines_N-cline-center-to-edge_m-constant 
##  [7] SS-Clines_N-cline-N-to-S_m-constant         
##  [8] SS-Clines_N-equal_m_breaks                  
##  [9] SS-Clines_N-equal_m-constant                
## [10] SS-Clines_N-variable_m-variable             
## [11] SS-Mtn_N-cline-center-to-edge_m-constant    
## [12] SS-Mtn_N-cline-N-to-S_m-constant            
## [13] SS-Mtn_N-equal_m_breaks                     
## [14] SS-Mtn_N-equal_m-constant                   
## [15] SS-Mtn_N-variable_m-variable                
## 15 Levels: SS-Clines_N-equal_m-constant ... Est-Clines_N-variable_m-variable
unique(stat_df$arch_level_sub)
## [1] 1 trait                            2 traits\nno pleiotropy\nequal S  
## [3] 2 traits\nno pleiotropy\nunequal S 2 traits\npleiotropy\nequal S     
## [5] 2 traits\npleiotropy\nunequal S   
## 5 Levels: 1 trait < ... < 2 traits\npleiotropy\nunequal S
unique(stat_df$arch)
##  [1] highly-polygenic_1-trait                        
##  [2] highly-polygenic_2-trait-no-pleiotropy-equal-S  
##  [3] highly-polygenic_2-trait-no-pleiotropy-unequal-S
##  [4] highly-polygenic_2-trait-pleiotropy-equal-S     
##  [5] highly-polygenic_2-trait-pleiotropy-unequal-S   
##  [6] mod-polygenic_1-trait                           
##  [7] mod-polygenic_2-trait-no-pleiotropy-equal-S     
##  [8] mod-polygenic_2-trait-no-pleiotropy-unequal-S   
##  [9] mod-polygenic_2-trait-pleiotropy-equal-S        
## [10] mod-polygenic_2-trait-pleiotropy-unequal-S      
## [11] oliogenic_1-trait                               
## [12] oliogenic_2-trait-no-pleiotropy-equal-S         
## [13] oliogenic_2-trait-no-pleiotropy-unequal-S       
## [14] oliogenic_2-trait-pleiotropy-equal-S            
## [15] oliogenic_2-trait-pleiotropy-unequal-S          
## 15 Levels: highly-polygenic_1-trait ...
## Statistical model with both traits
  stat_df$trait <- factor(stat_df$trait)
  levels(stat_df$trait)
## [1] "cor_TPR_sal"  "cor_TPR_temp"
  levels(stat_df$N_traits)
## NULL
  modelsum <- summary(aov(cor_TPR ~ trait + arch + demog + demog_level +  final_LA + arch*trait*demog, data=stat_df))
  modelsum
##                    Df Sum Sq Mean Sq F value Pr(>F)    
## trait               1  64.20   64.20 5513.30 <2e-16 ***
## arch               14 159.27   11.38  977.03 <2e-16 ***
## demog               1   4.39    4.39  377.02 <2e-16 ***
## demog_level         1  10.19   10.19  874.72 <2e-16 ***
## final_LA            1   1.06    1.06   91.11 <2e-16 ***
## trait:arch         11   9.11    0.83   71.15 <2e-16 ***
## arch:demog         14  15.03    1.07   92.22 <2e-16 ***
## trait:demog         1  38.34   38.34 3292.79 <2e-16 ***
## trait:arch:demog   11   1.76    0.16   13.77 <2e-16 ***
## Residuals        3994  46.50    0.01                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 450 observations deleted due to missingness
  ### Percent of variation (SS) explained by each explanatory variable
    pervar <- data.frame(variable = rownames(modelsum[[1]]), SS = modelsum[[1]][,2])
    pervar$pervar <- round(pervar$SS/sum(pervar$SS)*100, 1)
    pervar
##            variable         SS pervar
## 1  trait             64.195195   18.3
## 2  arch             159.267513   45.5
## 3  demog              4.389962    1.3
## 4  demog_level       10.185003    2.9
## 5  final_LA           1.060798    0.3
## 6  trait:arch         9.112923    2.6
## 7  arch:demog        15.033251    4.3
## 8  trait:demog       38.340187   11.0
## 9  trait:arch:demog   1.763571    0.5
## 10 Residuals         46.504897   13.3
## Statistical model with only temperature trait
  modelsum <- summary(aov(cor_TPR_temp ~ arch + demog + demog_level + final_LA + arch*demog*demog_level, data=final.df))
  pervar_temp <- data.frame(variable = rownames(modelsum[[1]]), SS = modelsum[[1]][,2])
  pervar_temp$pervar <- round(pervar_temp$SS/sum(pervar_temp$SS)*100, 1)
  pervar_temp
##           variable          SS pervar
## 1 arch             111.4892548   76.8
## 2 demog              7.5012931    5.2
## 3 demog_level        0.5870414    0.4
## 4 final_LA           0.1096110    0.1
## 5 arch:demog         4.6914989    3.2
## 6 arch:demog_level   0.4397451    0.3
## 7 Residuals         20.3182657   14.0
  ## Statistical model with only salinity trait
  modelsum <- summary(aov(cor_TPR_sal ~ arch + demog + demog_level +  final_LA + arch*demog*demog_level, data=final.df))
  pervar_sal <- data.frame(variable = rownames(modelsum[[1]]), SS = modelsum[[1]][,2])
  pervar_sal$pervar <- round(pervar_sal$SS/sum(pervar_sal$SS)*100, 1)
  pervar_sal
##           variable         SS pervar
## 1 arch             56.8911818   40.5
## 2 demog            38.5015498   27.4
## 3 demog_level      15.4485976   11.0
## 4 final_LA          0.2370578    0.2
## 5 arch:demog        9.6827706    6.9
## 6 arch:demog_level  1.0917684    0.8
## 7 Residuals        18.6684705   13.3
data.frame(variable = pervar_temp$variable, temp_AFcors = pervar_temp$pervar, sal_AFcors = pervar_sal$pervar)
##           variable temp_AFcors sal_AFcors
## 1 arch                    76.8       40.5
## 2 demog                    5.2       27.4
## 3 demog_level              0.4       11.0
## 4 final_LA                 0.1        0.2
## 5 arch:demog               3.2        6.9
## 6 arch:demog_level         0.3        0.8
## 7 Residuals               14.0       13.3

How does demography and genetic architecture contribute to the evolution of phenotypic clines without clines in causal allele frequencies?

Number of loci with correlations - demog

# Plote temperatue clines as a function of number of traits and landscape
a<- ggplot(final.df, aes(x=as.factor(N_traits), y=cor_TPR_temp, fill=demog_level)) + geom_boxplot(color="grey") + ggtheme + xlab("Number of traits") + ylab("Proportion of causal temp. \n loci with significant clines") + scale_fill_viridis(discrete=TRUE, option="viridis", begin=0, end=1) + theme(legend.position = "none") + ylim(0,1) + ggtitle("C")
a

# Plot Env2 clines as a function of landscape (only 2 trait simulations)
forb <- final.df[final.df$N_traits==2,]
forb$N_traits <- factor(forb$N_traits)
b<- ggplot(forb, aes(x=N_traits, y=cor_TPR_sal, fill=demog_level)) + geom_boxplot(color="grey") + ggtheme + xlab("Number of traits") + ylab("Proportion of causal Env2 \n loci with significant clines") +  scale_fill_viridis(discrete=TRUE, option="viridis", begin=0, end=1) + ylim(0,1) + guides(fill=guide_legend(title="Landscape")) + ggtitle("D")
b

### Pleiotropy vs no pleiotropy - only relevant for sims with 2 traits
  subdf_arch <- final.df[final.df$N_traits==2,]
  unique(final.df$SIGMA_K_1)
## [1] 0.5
  unique(subdf_arch$SIGMA_K_2)
## [1] 0.5 4.0
  subdf_arch$SIGMA_K_2 <- as.factor(subdf_arch$SIGMA_K_2)
  my_col_arch <- c(viridis(10)[3], viridis(10)[7])
  
  # temp only
  f1 <-   ggplot(subdf_arch, aes(x=arch_level, y=cor_TPR_temp, fill=as.factor(ispleiotropy))) + geom_boxplot(color="grey") + ggtheme + xlab("") + ylab("Proportion of causal temp. \n loci with significant clines") + scale_fill_manual( values=my_col_arch, labels=c("No pleiotropy", "Pleiotropy"), name="2-trait architectures")  + ylim(0,1) #+ theme(legend.title=element_text("2-trait\narchitectures"))
  f1

  # env2 only
  f2 <-   ggplot(subdf_arch, aes(x=arch_level, y=cor_TPR_sal, fill=as.factor(ispleiotropy))) + geom_boxplot(color="grey") + ggtheme + xlab("") + ylab("Proportion of causal sal. \n loci with significant clines") + scale_fill_manual( values=my_col_arch, labels=c("No pleiotropy", "Pleiotropy"), name="2-trait architectures")  + ylim(0,1) #+ theme(legend.title=element_text("2-trait\narchitectures"))
  f2

# Combine data together from f1 and f2 for a single plot
# because they both show the same pattern
pleiotropy.df <- gather(subdf_arch, key=trait, value=cor_TPR, cor_TPR_temp, cor_TPR_sal)

fboth <-   ggplot(pleiotropy.df, aes(x=arch_level, y=cor_TPR, fill=as.factor(ispleiotropy))) + geom_boxplot(color="grey") + ggtheme + xlab("") + ylab("Proportion of causal \n loci with significant clines") + scale_fill_manual( values=my_col_arch, labels=c("No pleiotropy", "Pleiotropy"), name="2-trait architectures")  + ylim(0,1) + ggtitle("B")
fboth

## Phenotypic clines vs. af clines

### For each trait, I want to plot the (correlation between the trait and environment) vs. (correlation between af and environment)
final.df$N_traits2 <- final.df$N_traits
final.df$N_traits2[final.df$N_traits==1] <- "1 Trait"
final.df$N_traits2[final.df$N_traits==2] <- "2 Traits"
final.df$ispleiotropy <- factor(final.df$ispleiotropy)
head(final.df$ispleiotropy)
## [1] No pleiotropy No pleiotropy No pleiotropy No pleiotropy No pleiotropy
## [6] No pleiotropy
## Levels: No pleiotropy Pleiotropy
f3 <- ggplot(final.df) + 
  geom_point(aes(x=subsamp_corr_phen_temp, y=cor_TPR_temp, color=arch_level#,shape=ispleiotropy
                 ), alpha=0.6, fill="grey", shape=0) +  
  geom_point(aes(x=subsamp_corr_phen_sal, y=cor_TPR_sal, color=arch_level#, shape=ispleiotropy
                 ), alpha=0.6, fill="grey", shape=0) + 
  ggtheme + ylim(0,1) + xlim(0,1)  +  
  xlab("Correlation(phenotype, deme environment)") + 
  ylab("Proportion of causal \n loci with significant clines") + scale_color_viridis(name="Genic level", discrete=TRUE, option="rocket", begin=0, end=0.9) + #scale_shape_manual(values=c(0,19),name="Pleiotropy") + 
  ggtitle("A") #+ #+ facet_grid(~N_traits2) 
   # facet_grid(~arch_level_sub)
f3
## Warning: Removed 450 rows containing missing values (geom_point).

# 450 missing values expected (simulations without the Env2 trait)

pdf(paste0(outputs,"WhatDrivesNonClines.pdf"), width=6, height=8)
  grid.arrange(f3, fboth,a,b, nrow=3, ncol=2, layout_matrix=matrix(c(1,1,2,2,3,4), nrow=3, byrow=TRUE))
## Warning: Removed 450 rows containing missing values (geom_point).
# 450 missing values expected (simulations without the Env2 trait)
dev.off()
## svg 
##   2

Percent of GWAS hits with clines

head(final.df$clinalparadigm_temp_propsigGWASclines)
## [1] 0.6050302 0.5794083 0.5593769 0.4777563 0.6314615 0.3099063
sum(is.na(final.df$clinalparadigm_temp_propsigGWASclines))
## [1] 1
plotdf <- data.frame(propsigGWASclines=c(final.df$clinalparadigm_sal_propsigGWASclines,final.df$clinalparadigm_temp_propsigGWASclines),
                     propClines=c(final.df$cor_TPR_sal,final.df$cor_TPR_temp),
                     arch_level=factor(rep("a",nrow(final.df)*2)))
plotdf$arch_level <- c(as.character(final.df$arch_level, final.df$arch_level))
str(plotdf)
## 'data.frame':    4500 obs. of  3 variables:
##  $ propsigGWASclines: num  NA NA NA NA NA NA NA NA NA NA ...
##  $ propClines       : num  NA NA NA NA NA NA NA NA NA NA ...
##  $ arch_level       : chr  "highly\npolygenic" "highly\npolygenic" "highly\npolygenic" "highly\npolygenic" ...
summary(lm(propsigGWASclines~propClines*arch_level, data=plotdf))
## 
## Call:
## lm(formula = propsigGWASclines ~ propClines * arch_level, data = plotdf)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.37677 -0.07902 -0.01619  0.05425  0.76866 
## 
## Coefficients:
##                                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                           0.001683   0.006292   0.268   0.7891    
## propClines                            1.051200   0.021509  48.872  < 2e-16 ***
## arch_levelmod.\npolygenic            -0.020949   0.009667  -2.167   0.0303 *  
## arch_leveloligogenic                  0.050248   0.010200   4.927 8.71e-07 ***
## propClines:arch_levelmod.\npolygenic -0.291569   0.027169 -10.732  < 2e-16 ***
## propClines:arch_leveloligogenic      -0.747232   0.024263 -30.797  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1321 on 4043 degrees of freedom
##   (451 observations deleted due to missingness)
## Multiple R-squared:  0.5648, Adjusted R-squared:  0.5642 
## F-statistic:  1049 on 5 and 4043 DF,  p-value: < 2.2e-16
pdf(paste0(outputs,"PropGWASClinal.pdf"), width=6, height=5)
ggplot(plotdf, aes(y=propsigGWASclines, 
                 x=propClines, color=arch_level)) + 
  geom_point( alpha=0.5) +xlim(0,1) + ylim(0,1) + ggtheme +
  geom_smooth(method="glm", level=0.95) + xlab("Proportion of QTNs that are clinal (ground truth)") + ylab("Proportion of GWAS hits that are clinal") + scale_color_viridis(name="Genic level", discrete=TRUE, option="rocket", begin=0, end=0.9) +
  geom_abline(intercept=0, slope=1, color="grey")
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 451 rows containing non-finite values (stat_smooth).
## Warning: Removed 451 rows containing missing values (geom_point).
## Warning: Removed 3 rows containing missing values (geom_smooth).
dev.off()
## svg 
##   2

Percent of Va explained by clinal loci

Same plots as above, but for the percent of the additive genetic variance (Va). If clinal loci explain a major proportion of Va, then it could be argued that QTN loci that do not have clinal patterns are not as “important” to discover.

# Reorganize data for plotting
pleiotropy.df2 <- gather(subdf_arch, key=trait, value=cor_VA_prop, cor_VA_temp_prop, cor_VA_sal_prop)
pleiotropy.df3 <- gather(subdf_arch, key=trait, value=cor_TPR, cor_TPR_temp, cor_TPR_sal)

fboth2 <-   ggplot() + 
  geom_boxplot(aes(x=arch_level, y=1-cor_TPR), data=pleiotropy.df3, color="grey70", alpha=0.8, fill="grey90") +
  geom_boxplot(aes(x=arch_level, y=1-cor_VA_prop, fill=arch_level), data=pleiotropy.df2, color="grey20") + ggtheme + xlab("") + ylab("Proportion of VA \n explained by non-clinal QTNs") + scale_fill_viridis(option="rocket", discrete=TRUE, end=1)  + ylim(0,1) + ggtitle("A") + theme(legend.position = "none")
fboth2

a1<- ggplot() + 
  geom_boxplot(aes(x=demog_level, y=1-cor_TPR_temp), data=final.df, color="grey70", alpha=0.8, fill="grey90") +
  geom_boxplot(data=final.df, aes(x=demog_level, y=1-cor_VA_temp_prop, fill=demog_level),color="grey20") + ggtheme + xlab("Landscape") + ylab("Proportion of VA in temp. \n explained by non-clinal QTNs") + scale_fill_viridis(discrete=TRUE, option="viridis", begin=0, end=1) + theme(legend.position = "none")+ ylim(0,1) + ggtitle("A")
a1

b1<- ggplot()+
    geom_boxplot(aes(x=demog_level, y=1-cor_TPR_sal), data=final.df, color="grey70", alpha=0.8, fill="grey90") +
  geom_boxplot(data=final.df, aes(x=demog_level, y=1-cor_VA_sal_prop, fill=demog_level),color="grey20") + ggtheme + xlab("Landscape") + ylab("Proportion of VA in Env2 \n explained by non-clinal QTNs") + scale_fill_viridis(discrete=TRUE, option="viridis", begin=0, end=1) + theme(legend.position = "none")+ ylim(0,1) + ggtitle("B")
b1
## Warning: Removed 450 rows containing non-finite values (stat_boxplot).

pdf(paste0(outputs,"WhatDrivesNonClines_VA.pdf"), width=7, height=3)
 # grid.arrange(fboth2, a1,b1, nrow=2, ncol=2, layout_matrix=matrix(c(1,1,2,3), nrow=2, byrow=TRUE))
  grid.arrange(a1,b1, ncol=2)
## Warning: Removed 450 rows containing non-finite values (stat_boxplot).
dev.off()
## svg 
##   2

Demography sub level

unique(final.df$demog)
## [1] Estuary SS     
## Levels: Estuary SS
unique(final.df$demog_level)
## [1] Est-Clines SS-Clines  SS-Mtn    
## Levels: SS-Clines < SS-Mtn < Est-Clines
unique(final.df$demog_level_sub)
## [1] N central cline\nm constant  N latitude cline\nm constant
## [3] N equal\nm breaks            N equal\nm constant         
## [5] N variable\nm variable      
## 5 Levels: N equal\nm constant < ... < N variable\nm variable
pleiotropy.df$demog_level_sub <- as.factor(pleiotropy.df$demog_level_sub)
levels(pleiotropy.df$demog_level_sub) <- c("N equal\nm constant", "N equal\nm breaks", "N latitude cline\nm constant", "N central cline\nm constant",  "N variable\nm variable") # make sure in correct order




## Sub demograph - mako color

d1 <- ggplot(pleiotropy.df, aes(x=as.factor(demog_level_sub), y=cor_TPR, fill=as.factor(demog_level_sub))) + geom_boxplot(color="grey") + ggtheme + xlab("Demography") + ylab("Proportion of causal loci\nwith significant clines") + scale_fill_viridis(option="mako",discrete=TRUE) + theme(legend.position = "none") + theme( axis.text.x=element_text(angle=90,vjust=0.5, hjust=1, size = 10)) + ggtitle("A")
d1

## Strength of selection - magma color
my_col_S <- c(magma(10)[5], magma(10)[8])

s1<- ggplot(subdf_arch, aes(x=arch_level, y=cor_TPR_temp, fill=as.factor(SIGMA_K_2))) + geom_boxplot(color="grey") + ggtheme + xlab("") + ylab("Proportion of causal temp. \n loci with significant clines") + scale_fill_manual( values=my_col_S, labels=c(
  expression(paste("Strong selection ", sigma[K]," = 0.5")), 
  expression(paste("Weak selection ", sigma[K]," = 4.0"))
  ), name="2-trait architectures")  + ylim(0,1) + xlab("Genetic architecture") + ggtitle("B")
s1

pdf(paste0(outputs,"WhatDrivesNonClines-subdemog-selection.pdf"), width=6, height=8)
  grid.arrange(d1, s1, nrow=2)
dev.off()
## svg 
##   2

Does hanging strength of selection on trait 1 (temp) affect the number of allee frequency clines that evolve in trait 2 (env2)? Graph suggests no.

 #+ theme(legend.title=element_text("2-trait\narchitectures"))

ggplot(subdf_arch, aes(x=arch_level, y=cor_TPR_sal, fill=as.factor(SIGMA_K_2))) + geom_boxplot(color="grey") + ggtheme + xlab("") + ylab("Proportion of causal sal. \n loci with significant clines") + scale_fill_manual( values=my_col_S, labels=c("Strong selection on other trait (sigma_K=0.5)", "Weak selection on other trait (sigma_K=4)"), name="2-trait architectures")  + ylim(0,1) #+ theme(legend.title=element_text("2-trait\narchitectures"))

Distribution of the correlation between structure and deme environment

sum(is.na(final.df$cor_PC1_temp))
## [1] 0
# First PC axis with temp
sc1<- ggplot(final.df) + geom_histogram(aes(x=abs(cor_PC1_temp), fill=demog_level_sub), binwidth=0.05, color="grey") + ggtheme + coord_cartesian(xlim = c(0, 1)) + facet_grid(demog_level~., scales = "free_y") + scale_fill_viridis(option="mako", discrete=TRUE, name="Demography level") + xlab("|Cor(PC1, deme Temperature)|") + ylab("Number of simulations")  + theme(legend.position="none") + ggtitle("A) Temperature")
sc1

# 2nd PC axis with temp
sc2<-ggplot(final.df) + geom_histogram(aes(x=abs(cor_PC2_temp), fill=demog_level_sub), binwidth=0.05, color="grey") + ggtheme + coord_cartesian(xlim = c(0, 1)) + facet_grid(demog_level~., scales = "free_y") + scale_fill_viridis(option="mako", discrete=TRUE, name="Demography level") + xlab("|Cor(PC2, deme temp)|") + ylab("Number of simulations")  + theme(legend.position="none") 
sc2

# 1st PC axis with Env2
sc3<-ggplot(final.df) + geom_histogram(aes(x=abs(cor_PC1_sal), fill=demog_level_sub), binwidth=0.05, color="grey") + ggtheme + coord_cartesian(xlim = c(0, 1)) + facet_grid(demog_level~., scales = "free_y") + scale_fill_viridis(option="mako", discrete=TRUE, name="Demography") + xlab("|Cor(PC1, deme Env2)|") + ylab("Number of simulations")  + ggtitle("B) Env2") + theme(legend.position="right")
sc3

# 2nd PC axis with Env2
sc4<-ggplot(final.df) + geom_histogram(aes(x=abs(cor_PC2_sal), fill=demog_level_sub), binwidth=0.05,  color="grey") + ggtheme + coord_cartesian(xlim = c(0, 1)) + facet_grid(demog_level~., scales = "free_y") + scale_fill_viridis(option="mako", discrete=TRUE, name="Demography level") + xlab("|Cor(PC2, deme Env2)|") + ylab("Number of simulations")  + theme(legend.position="bottom")
sc4

pdf(paste0(outputs,"StructureEnvCor_facetDemog.pdf"), width=12, height=9)
    grid.arrange(sc1, sc3, layout_matrix=matrix(c(1,1,1,2,2,2,2),
                                              nrow=1), nrow=1)
dev.off()
## svg 
##   2

Under what conditions can we reliably identify the alleles with effects on adaptive phenotypes using genetic-environment associations (latent factor mixed models, uncorrected correlations, and redundancy analysis)?

Compare methods AUC

AUC stands for area under the curve, here I use the Precision-Recall curve

# Check for missing data
sum(is.na(final.df$cor_AUCPR_temp_neutSNPs))
## [1] 0
sum(is.na(final.df$cor_AUCPR_sal_neutSNPs)) #expected 450 missing
## [1] 450
sum(is.na(final.df$LEA3.2_lfmm2_AUCPR_temp_neutSNPs))
## [1] 0
sum(is.na(final.df$LEA3.2_lfmm2_AUCPR_sal_neutSNPs)) #expected 450 missing
## [1] 450
sum(is.na(final.df$RDA_AUCPR_neutSNPs))
## [1] 0
sum(is.na(final.df$RDA_AUCPR_neutSNPs_corr))
## [1] 0
# Reorganize data for plotting
comparemethods.AUC <- gather(final.df, key=method, value=AUCPR, cor_AUCPR_temp_neutSNPs, LEA3.2_lfmm2_AUCPR_temp_neutSNPs, RDA_AUCPR_neutSNPs, RDA_AUCPR_neutSNPs_corr, cor_AUCPR_sal_neutSNPs,
                                  LEA3.2_lfmm2_AUCPR_sal_neutSNPs)


levels(factor(comparemethods.AUC$method))
## [1] "cor_AUCPR_sal_neutSNPs"           "cor_AUCPR_temp_neutSNPs"         
## [3] "LEA3.2_lfmm2_AUCPR_sal_neutSNPs"  "LEA3.2_lfmm2_AUCPR_temp_neutSNPs"
## [5] "RDA_AUCPR_neutSNPs"               "RDA_AUCPR_neutSNPs_corr"
comparemethods.AUC$methodtype <- factor(comparemethods.AUC$method)

comparemethods.AUC$methodtype <- 
  revalue(comparemethods.AUC$methodtype,
          c(
            "cor_AUCPR_temp_neutSNPs"= "Cor(p, Temp.)",  
            "LEA3.2_lfmm2_AUCPR_temp_neutSNPs" = "LFMM - Temp\n(structure correction)",
            "cor_AUCPR_sal_neutSNPs"="Cor(p, Env2)", 
            "LEA3.2_lfmm2_AUCPR_sal_neutSNPs" = "LFMM - Env2\n(structure correction)",
            "RDA_AUCPR_neutSNPs"  = "RDA",        
             "RDA_AUCPR_neutSNPs_corr" = "pRDA\n(structure correction)"  ))

comparemethods.AUC$methodtype <- factor(comparemethods.AUC$methodtype,
                                        levels = c("Cor(p, Temp.)",
                                                   "LFMM - Temp\n(structure correction)",
                                                   "Cor(p, Env2)",
                                                   "LFMM - Env2\n(structure correction)",
                                                   "RDA",
                                                    "pRDA\n(structure correction)"),
                                        ordered=TRUE)

# Sanity checks  
levels(comparemethods.AUC$methodtype)
## [1] "Cor(p, Temp.)"                       "LFMM - Temp\n(structure correction)"
## [3] "Cor(p, Env2)"                        "LFMM - Env2\n(structure correction)"
## [5] "RDA"                                 "pRDA\n(structure correction)"
table(comparemethods.AUC$methodtype)
## 
##                       Cor(p, Temp.) LFMM - Temp\n(structure correction) 
##                                2250                                2250 
##                        Cor(p, Env2) LFMM - Env2\n(structure correction) 
##                                2250                                2250 
##                                 RDA        pRDA\n(structure correction) 
##                                2250                                2250
summary(comparemethods.AUC$AUCPR)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##  0.0000  0.0314  0.0890  0.2013  0.2791  1.0000     900
# Across all simulations, AUCPR
g <- ggplot(comparemethods.AUC, aes(x=as.factor(methodtype), y=AUCPR)) + geom_boxplot(color="grey",  fill=rep(c("darkblue", "cornflowerblue"),3)) + ggtheme + xlab("method") + ylab("AUC-PR\n(worse <<--->> better)")   + theme( axis.text.x=element_text(angle=90,vjust=0.5, hjust=1, size = 10)) + scale_color_viridis(name="Landscape", discrete=TRUE) + guides(fill=guide_legend(title="Landscape")) +ggtitle("A")
g
## Warning: Removed 900 rows containing non-finite values (stat_boxplot).

# tried a violin plot, but the boxplot is better
# 450 NAs are expected for the Env2 models
tapply(comparemethods.AUC$AUCPR,comparemethods.AUC$methodtype, function(x){sum(is.na(x))})
##                       Cor(p, Temp.) LFMM - Temp\n(structure correction) 
##                                   0                                   0 
##                        Cor(p, Env2) LFMM - Env2\n(structure correction) 
##                                 450                                 450 
##                                 RDA        pRDA\n(structure correction) 
##                                   0                                   0

Compare methods FDR

False discovery rate (FDR) is the proportion of positive tests that are true positives. If there are no positive tests, then the statistic is undefined (NA).

#Check for NAs in temperature models
  sum(is.na(final.df$cor_FDR_neutSNPs_temp))
## [1] 0
  sum(is.na(final.df$LEA3.2_lfmm2_FDR_neutSNPs_temp))
## [1] 697
    # A lot of NAs here

  # Check NAs in FDR or temp/salinity model come from cases with 0 outliers
    table(isFDR_NA=is.na(final.df$LEA3.2_lfmm2_FDR_neutSNPs_temp), 
          is_0_outliers=(final.df$LEA3.2_lfmm2_num_causal_sig_temp==0 & 
                           final.df$LEA3.2_lfmm2_num_neut_sig_temp==0))
##         is_0_outliers
## isFDR_NA FALSE TRUE
##    FALSE  1553    0
##    TRUE      0  697
    table(isFDR_NA=is.na(final.df$LEA3.2_lfmm2_FDR_neutSNPs_sal), 
          is_0_outliers=(final.df$LEA3.2_lfmm2_num_causal_sig_sal==0 & 
                           final.df$LEA3.2_lfmm2_num_neut_sig_sal==0))
##         is_0_outliers
## isFDR_NA FALSE TRUE
##    FALSE  1689    0
##    TRUE      0  561
  tapply(is.na(final.df$LEA3.2_lfmm2_FDR_neutSNPs_temp), 
         list(final.df$demog_level, final.df$demog_level_sub), sum)
##            N equal\nm constant N equal\nm breaks N latitude cline\nm constant
## SS-Clines                   40                41                           62
## SS-Mtn                      45                63                           55
## Est-Clines                  31                34                           54
##            N central cline\nm constant N variable\nm variable
## SS-Clines                           50                     53
## SS-Mtn                              56                     58
## Est-Clines                           9                     46
      ## NAs are evenly spread across the demographies, but slightly higher in the SS scenarios
   
#Check for NAs in RDA model
  sum(is.na(final.df$RDA_FDR_neutSNPs))
## [1] 2
  sum(is.na(final.df$RDA_FDR_neutSNPs_corr))
## [1] 0
# reorganize data for plotting
comparemethods.FDR <- gather(final.df, key=method, value=FDR, cor_FDR_neutSNPs_temp, LEA3.2_lfmm2_FDR_neutSNPs_temp, RDA_FDR_neutSNPs, RDA_FDR_neutSNPs_corr, cor_FDR_neutSNPs_sal, LEA3.2_lfmm2_FDR_neutSNPs_sal)

comparemethods.FDR <- comparemethods.FDR[order(comparemethods.FDR$seed),]
tail(comparemethods.FDR)
##          seed
## 2250  1233343
## 4500  1233343
## 6750  1233343
## 9000  1233343
## 11250 1233343
## 13500 1233343
##                                                                      level reps
## 2250  oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
## 4500  oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
## 6750  oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
## 9000  oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
## 11250 oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
## 13500 oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
##                                         arch                   demog_name
## 2250  oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
## 4500  oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
## 6750  oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
## 9000  oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
## 11250 oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
## 13500 oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
##              demog_level_sub demog_level MIG_x MIG_y xcline ycline demog
## 2250  N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
## 4500  N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
## 6750  N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
## 9000  N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
## 11250 N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
## 13500 N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
##       METAPOP_SIDE_x METAPOP_SIDE_y Nequal isVariableM MIG_breaks
## 2250              10             10      3           1          0
## 4500              10             10      3           1          0
## 6750              10             10      3           1          0
## 9000              10             10      3           1          0
## 11250             10             10      3           1          0
## 13500             10             10      3           1          0
##                        arch_level_sub arch_level MU_base MU_QTL_proportion
## 2250  2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
## 4500  2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
## 6750  2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
## 9000  2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
## 11250 2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
## 13500 2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
##       SIGMA_QTN_1 SIGMA_QTN_2 SIGMA_K_1 SIGMA_K_2 N_traits ispleiotropy
## 2250          0.4         0.4       0.5         4        2   Pleiotropy
## 4500          0.4         0.4       0.5         4        2   Pleiotropy
## 6750          0.4         0.4       0.5         4        2   Pleiotropy
## 9000          0.4         0.4       0.5         4        2   Pleiotropy
## 11250         0.4         0.4       0.5         4        2   Pleiotropy
## 13500         0.4         0.4       0.5         4        2   Pleiotropy
##       n_samp_tot n_samp_per_pop sd_fitness_among_inds sd_fitness_among_pops
## 2250        1000             10             0.1193353             0.0675856
## 4500        1000             10             0.1193353             0.0675856
## 6750        1000             10             0.1193353             0.0675856
## 9000        1000             10             0.1193353             0.0675856
## 11250       1000             10             0.1193353             0.0675856
## 13500       1000             10             0.1193353             0.0675856
##       final_LA K   Bonf_alpha numCausalLowMAFsample all_corr_phen_temp
## 2250  0.361984 1 6.179706e-06                     0          0.8163458
## 4500  0.361984 1 6.179706e-06                     0          0.8163458
## 6750  0.361984 1 6.179706e-06                     0          0.8163458
## 9000  0.361984 1 6.179706e-06                     0          0.8163458
## 11250 0.361984 1 6.179706e-06                     0          0.8163458
## 13500 0.361984 1 6.179706e-06                     0          0.8163458
##       subsamp_corr_phen_temp all_corr_phen_sal subsamp_corr_phen_sal
## 2250               0.6347974          0.884965             0.7608153
## 4500               0.6347974          0.884965             0.7608153
## 6750               0.6347974          0.884965             0.7608153
## 9000               0.6347974          0.884965             0.7608153
## 11250              0.6347974          0.884965             0.7608153
## 13500              0.6347974          0.884965             0.7608153
##       num_causal_prefilter num_causal_postfilter num_non_causal
## 2250                    12                     8           8083
## 4500                    12                     8           8083
## 6750                    12                     8           8083
## 9000                    12                     8           8083
## 11250                   12                     8           8083
## 13500                   12                     8           8083
##       num_neut_prefilter num_neut_postfilter num_neut_neutralgenome
## 2250                8197                8197                   3947
## 4500                8197                8197                   3947
## 6750                8197                8197                   3947
## 9000                8197                8197                   3947
## 11250               8197                8197                   3947
## 13500               8197                8197                   3947
##       num_causal_temp num_causal_sal num_multiallelic   meanFst va_temp_total
## 2250                8              8                0 0.1737941    0.08556485
## 4500                8              8                0 0.1737941    0.08556485
## 6750                8              8                0 0.1737941    0.08556485
## 9000                8              8                0 0.1737941    0.08556485
## 11250               8              8                0 0.1737941    0.08556485
## 13500               8              8                0 0.1737941    0.08556485
##       va_sal_total Va_temp_sample Va_sal_sample nSNPs median_causal_temp_cor
## 2250      0.105924     0.08049695    0.09935857  8091              0.3033895
## 4500      0.105924     0.08049695    0.09935857  8091              0.3033895
## 6750      0.105924     0.08049695    0.09935857  8091              0.3033895
## 9000      0.105924     0.08049695    0.09935857  8091              0.3033895
## 11250     0.105924     0.08049695    0.09935857  8091              0.3033895
## 13500     0.105924     0.08049695    0.09935857  8091              0.3033895
##       median_causal_sal_cor median_neut_temp_cor median_neut_sal_cor
## 2250              0.3424647             0.248889           0.1358742
## 4500              0.3424647             0.248889           0.1358742
## 6750              0.3424647             0.248889           0.1358742
## 9000              0.3424647             0.248889           0.1358742
## 11250             0.3424647             0.248889           0.1358742
## 13500             0.3424647             0.248889           0.1358742
##       cor_VA_temp_prop cor_VA_sal_prop cor_TPR_temp cor_TPR_sal
## 2250         0.3901235       0.8777962        0.375         0.5
## 4500         0.3901235       0.8777962        0.375         0.5
## 6750         0.3901235       0.8777962        0.375         0.5
## 9000         0.3901235       0.8777962        0.375         0.5
## 11250        0.3901235       0.8777962        0.375         0.5
## 13500        0.3901235       0.8777962        0.375         0.5
##       cor_FDR_allSNPs_temp cor_FDR_allSNPs_sal num_causal_sig_temp_corr
## 2250             0.9987903           0.9913043                        3
## 4500             0.9987903           0.9913043                        3
## 6750             0.9987903           0.9913043                        3
## 9000             0.9987903           0.9913043                        3
## 11250            0.9987903           0.9913043                        3
## 13500            0.9987903           0.9913043                        3
##       num_causal_sig_sal_corr num_notCausal_sig_temp_corr
## 2250                        4                        2477
## 4500                        4                        2477
## 6750                        4                        2477
## 9000                        4                        2477
## 11250                       4                        2477
## 13500                       4                        2477
##       num_notCausal_sig_sal_corr num_neut_sig_temp_corr num_neut_sig_sal_corr
## 2250                         456                   1195                   152
## 4500                         456                   1195                   152
## 6750                         456                   1195                   152
## 9000                         456                   1195                   152
## 11250                        456                   1195                   152
## 13500                        456                   1195                   152
##       cor_AUCPR_temp_allSNPs cor_AUCPR_temp_neutSNPs cor_AUCPR_sal_allSNPs
## 2250             0.001387016             0.002938006            0.02439708
## 4500             0.001387016             0.002938006            0.02439708
## 6750             0.001387016             0.002938006            0.02439708
## 9000             0.001387016             0.002938006            0.02439708
## 11250            0.001387016             0.002938006            0.02439708
## 13500            0.001387016             0.002938006            0.02439708
##       cor_AUCPR_sal_neutSNPs cor_af_temp_noutliers cor_af_sal_noutliers
## 2250               0.2860155                  2480                  460
## 4500               0.2860155                  2480                  460
## 6750               0.2860155                  2480                  460
## 9000               0.2860155                  2480                  460
## 11250              0.2860155                  2480                  460
## 13500              0.2860155                  2480                  460
##       cor_FPR_temp_neutSNPs cor_FPR_sal_neutSNPs LEA3.2_lfmm2_Va_temp_prop
## 2250              0.3027616           0.03851026                         0
## 4500              0.3027616           0.03851026                         0
## 6750              0.3027616           0.03851026                         0
## 9000              0.3027616           0.03851026                         0
## 11250             0.3027616           0.03851026                         0
## 13500             0.3027616           0.03851026                         0
##       LEA3.2_lfmm2_Va_sal_prop LEA3.2_lfmm2_TPR_temp LEA3.2_lfmm2_TPR_sal
## 2250                 0.8777962                     0                  0.5
## 4500                 0.8777962                     0                  0.5
## 6750                 0.8777962                     0                  0.5
## 9000                 0.8777962                     0                  0.5
## 11250                0.8777962                     0                  0.5
## 13500                0.8777962                     0                  0.5
##       LEA3.2_lfmm2_FDR_allSNPs_temp LEA3.2_lfmm2_FDR_allSNPs_sal
## 2250                             NA                    0.9090909
## 4500                             NA                    0.9090909
## 6750                             NA                    0.9090909
## 9000                             NA                    0.9090909
## 11250                            NA                    0.9090909
## 13500                            NA                    0.9090909
##       LEA3.2_lfmm2_AUCPR_temp_allSNPs LEA3.2_lfmm2_AUCPR_temp_neutSNPs
## 2250                        0.2117759                        0.5088647
## 4500                        0.2117759                        0.5088647
## 6750                        0.2117759                        0.5088647
## 9000                        0.2117759                        0.5088647
## 11250                       0.2117759                        0.5088647
## 13500                       0.2117759                        0.5088647
##       LEA3.2_lfmm2_AUCPR_sal_allSNPs LEA3.2_lfmm2_AUCPR_sal_neutSNPs
## 2250                       0.2117759                       0.5088647
## 4500                       0.2117759                       0.5088647
## 6750                       0.2117759                       0.5088647
## 9000                       0.2117759                       0.5088647
## 11250                      0.2117759                       0.5088647
## 13500                      0.2117759                       0.5088647
##       LEA3.2_lfmm2_mlog10P_tempenv_noutliers
## 2250                                       0
## 4500                                       0
## 6750                                       0
## 9000                                       0
## 11250                                      0
## 13500                                      0
##       LEA3.2_lfmm2_mlog10P_salenv_noutliers LEA3.2_lfmm2_num_causal_sig_temp
## 2250                                     44                                0
## 4500                                     44                                0
## 6750                                     44                                0
## 9000                                     44                                0
## 11250                                    44                                0
## 13500                                    44                                0
##       LEA3.2_lfmm2_num_neut_sig_temp LEA3.2_lfmm2_num_causal_sig_sal
## 2250                               0                               4
## 4500                               0                               4
## 6750                               0                               4
## 9000                               0                               4
## 11250                              0                               4
## 13500                              0                               4
##       LEA3.2_lfmm2_num_neut_sig_sal LEA3.2_lfmm2_FPR_neutSNPs_temp
## 2250                              0                              0
## 4500                              0                              0
## 6750                              0                              0
## 9000                              0                              0
## 11250                             0                              0
## 13500                             0                              0
##       LEA3.2_lfmm2_FPR_neutSNPs_sal RDA1_propvar RDA2_propvar RDA1_propvar_corr
## 2250                              0        0.739        0.261             0.673
## 4500                              0        0.739        0.261             0.673
## 6750                              0        0.739        0.261             0.673
## 9000                              0        0.739        0.261             0.673
## 11250                             0        0.739        0.261             0.673
## 13500                             0        0.739        0.261             0.673
##       RDA2_propvar_corr RDA1_temp_cor RDA1_sal_cor RDA2_temp_cor RDA2_sal_cor
## 2250              0.327     0.9800515    0.1987435    -0.1987435    0.9800515
## 4500              0.327     0.9800515    0.1987435    -0.1987435    0.9800515
## 6750              0.327     0.9800515    0.1987435    -0.1987435    0.9800515
## 9000              0.327     0.9800515    0.1987435    -0.1987435    0.9800515
## 11250             0.327     0.9800515    0.1987435    -0.1987435    0.9800515
## 13500             0.327     0.9800515    0.1987435    -0.1987435    0.9800515
##       RDA_Va_temp_prop RDA_Va_temp_prop_corr RDA_Va_sal_prop
## 2250         0.8073374             0.8955353       0.8777962
## 4500         0.8073374             0.8955353       0.8777962
## 6750         0.8073374             0.8955353       0.8777962
## 9000         0.8073374             0.8955353       0.8777962
## 11250        0.8073374             0.8955353       0.8777962
## 13500        0.8073374             0.8955353       0.8777962
##       RDA_Va_sal_prop_corr RDA_TPR RDA_TPR_corr RDA_FDR_allSNPs
## 2250             0.9096928     0.5        0.625        0.983871
## 4500             0.9096928     0.5        0.625        0.983871
## 6750             0.9096928     0.5        0.625        0.983871
## 9000             0.9096928     0.5        0.625        0.983871
## 11250            0.9096928     0.5        0.625        0.983871
## 13500            0.9096928     0.5        0.625        0.983871
##       RDA_FDR_allSNPs_corr num_RDA_sig_causal num_RDA_sig_neutral
## 2250             0.9814815                  4                  62
## 4500             0.9814815                  4                  62
## 6750             0.9814815                  4                  62
## 9000             0.9814815                  4                  62
## 11250            0.9814815                  4                  62
## 13500            0.9814815                  4                  62
##       num_RDA_sig_causal_corr num_RDA_sig_neutral_corr RDA_AUCPR_allSNPs
## 2250                        5                       92          0.203218
## 4500                        5                       92          0.203218
## 6750                        5                       92          0.203218
## 9000                        5                       92          0.203218
## 11250                       5                       92          0.203218
## 13500                       5                       92          0.203218
##       RDA_AUCPR_neutSNPs RDA_AUCPR_neutSNPs_corr RDA_FPR_neutSNPs
## 2250           0.5029961                0.332056       0.01570813
## 4500           0.5029961                0.332056       0.01570813
## 6750           0.5029961                0.332056       0.01570813
## 9000           0.5029961                0.332056       0.01570813
## 11250          0.5029961                0.332056       0.01570813
## 13500          0.5029961                0.332056       0.01570813
##       RDA_FPR_neutSNPs_corr RDA_RDAmutpred_cor_tempEffect
## 2250             0.02330884                           0.5
## 4500             0.02330884                           0.5
## 6750             0.02330884                           0.5
## 9000             0.02330884                           0.5
## 11250            0.02330884                           0.5
## 13500            0.02330884                           0.5
##       RDA_RDAmutpred_cor_salEffect RDA_absRDAmutpred_cor_tempVa
## 2250                     0.2857143                   0.02069674
## 4500                     0.2857143                   0.02069674
## 6750                     0.2857143                   0.02069674
## 9000                     0.2857143                   0.02069674
## 11250                    0.2857143                   0.02069674
## 13500                    0.2857143                   0.02069674
##       RDA_absRDAmutpred_cor_salVa RDA_RDAmutpred_cor_tempEffect_structcorr
## 2250                   0.02400657                                0.2752112
## 4500                   0.02400657                                0.2752112
## 6750                   0.02400657                                0.2752112
## 9000                   0.02400657                                0.2752112
## 11250                  0.02400657                                0.2752112
## 13500                  0.02400657                                0.2752112
##       RDA_RDAmutpred_cor_salEffect_structcorr
## 2250                                0.6602084
## 4500                                0.6602084
## 6750                                0.6602084
## 9000                                0.6602084
## 11250                               0.6602084
## 13500                               0.6602084
##       RDA_absRDAmutpred_cor_tempVa_structcorr
## 2250                               0.08556552
## 4500                               0.08556552
## 6750                               0.08556552
## 9000                               0.08556552
## 11250                              0.08556552
## 13500                              0.08556552
##       RDA_absRDAmutpred_cor_salVa_structcorr
## 2250                               0.1153435
## 4500                               0.1153435
## 6750                               0.1153435
## 9000                               0.1153435
## 11250                              0.1153435
## 13500                              0.1153435
##       RDA_cor_RDA20000temppredict_tempPhen RDA_cor_RDA20000salpredict_salPhen
## 2250                             0.5661217                          0.6653819
## 4500                             0.5661217                          0.6653819
## 6750                             0.5661217                          0.6653819
## 9000                             0.5661217                          0.6653819
## 11250                            0.5661217                          0.6653819
## 13500                            0.5661217                          0.6653819
##       RDA_cor_RDA20000temppredict_tempPhen_structcorr
## 2250                                         0.238542
## 4500                                         0.238542
## 6750                                         0.238542
## 9000                                         0.238542
## 11250                                        0.238542
## 13500                                        0.238542
##       RDA_cor_RDA20000salpredict_salPhen_structcorr cor_PC1_temp cor_PC1_sal
## 2250                                      0.6262283    0.7832223  0.09915203
## 4500                                      0.6262283    0.7832223  0.09915203
## 6750                                      0.6262283    0.7832223  0.09915203
## 9000                                      0.6262283    0.7832223  0.09915203
## 11250                                     0.6262283    0.7832223  0.09915203
## 13500                                     0.6262283    0.7832223  0.09915203
##       cor_PC2_temp cor_PC2_sal cor_LFMMU1_temp cor_LFMMU1_sal cor_LFMMU2_temp
## 2250    -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
## 4500    -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
## 6750    -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
## 9000    -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
## 11250   -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
## 13500   -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
##       cor_LFMMU2_sal cor_PC1_LFMMU1_temp cor_PC1_LFMMU1_sal cor_PC2_LFMMU1_temp
## 2250              NA           0.8090855         -0.9986383           0.5807664
## 4500              NA           0.8090855         -0.9986383           0.5807664
## 6750              NA           0.8090855         -0.9986383           0.5807664
## 9000              NA           0.8090855         -0.9986383           0.5807664
## 11250             NA           0.8090855         -0.9986383           0.5807664
## 13500             NA           0.8090855         -0.9986383           0.5807664
##       cor_PC2_LFMMU1_sal gwas_TPR_sal gwas_TPR_temp gwas_FDR_sal_neutbase
## 2250         -0.02590842         0.75         0.875              0.997544
## 4500         -0.02590842         0.75         0.875              0.997544
## 6750         -0.02590842         0.75         0.875              0.997544
## 9000         -0.02590842         0.75         0.875              0.997544
## 11250        -0.02590842         0.75         0.875              0.997544
## 13500        -0.02590842         0.75         0.875              0.997544
##       gwas_FDR_temp_neutbase clinalparadigm_sal_proptop5GWASclines
## 2250                0.996434                             0.5333333
## 4500                0.996434                             0.5333333
## 6750                0.996434                             0.5333333
## 9000                0.996434                             0.5333333
## 11250               0.996434                             0.5333333
## 13500               0.996434                             0.5333333
##       clinalparadigm_temp_proptop5GWASclines
## 2250                               0.2074074
## 4500                               0.2074074
## 6750                               0.2074074
## 9000                               0.2074074
## 11250                              0.2074074
## 13500                              0.2074074
##       clinalparadigm_sal_propsigGWASclines
## 2250                            0.09349593
## 4500                            0.09349593
## 6750                            0.09349593
## 9000                            0.09349593
## 11250                           0.09349593
## 13500                           0.09349593
##       clinalparadigm_temp_propsigGWASclines N_traits2
## 2250                              0.2850657  2 Traits
## 4500                              0.2850657  2 Traits
## 6750                              0.2850657  2 Traits
## 9000                              0.2850657  2 Traits
## 11250                             0.2850657  2 Traits
## 13500                             0.2850657  2 Traits
##                               method       FDR
## 2250           cor_FDR_neutSNPs_temp 0.9974958
## 4500  LEA3.2_lfmm2_FDR_neutSNPs_temp        NA
## 6750                RDA_FDR_neutSNPs 0.9393939
## 9000           RDA_FDR_neutSNPs_corr 0.9484536
## 11250           cor_FDR_neutSNPs_sal 0.9743590
## 13500  LEA3.2_lfmm2_FDR_neutSNPs_sal 0.0000000
comparemethods.FDR$methodtype <- factor(comparemethods.FDR$method)

levels(comparemethods.FDR$methodtype)
## [1] "cor_FDR_neutSNPs_sal"           "cor_FDR_neutSNPs_temp"         
## [3] "LEA3.2_lfmm2_FDR_neutSNPs_sal"  "LEA3.2_lfmm2_FDR_neutSNPs_temp"
## [5] "RDA_FDR_neutSNPs"               "RDA_FDR_neutSNPs_corr"
comparemethods.FDR$methodtype <- revalue(comparemethods.FDR$methodtype,
                                         c("cor_FDR_neutSNPs_sal"="Cor(p, Env2)", 
                                           "cor_FDR_neutSNPs_temp"= "Cor(p, Temp.)",  
                                           "LEA3.2_lfmm2_FDR_neutSNPs_sal" =  "LFMM - Temp.\n(structure correction)",
                                           "LEA3.2_lfmm2_FDR_neutSNPs_temp" = "LFMM - Env2\n(structure correction)",
                                           "RDA_FDR_neutSNPs"  = "RDA"   ,        
                                           "RDA_FDR_neutSNPs_corr" = "pRDA\n(structure correction)" ))

comparemethods.FDR$methodtype <- factor(comparemethods.FDR$methodtype,
                                        levels = c("Cor(p, Temp.)",
                                                   "LFMM - Temp.\n(structure correction)",
                                                   "Cor(p, Env2)",
                                                   "LFMM - Env2\n(structure correction)",
                                                   "RDA",
                                                    "pRDA\n(structure correction)"),
                                        ordered=TRUE)

table(comparemethods.FDR$methodtype)  
## 
##                        Cor(p, Temp.) LFMM - Temp.\n(structure correction) 
##                                 2250                                 2250 
##                         Cor(p, Env2)  LFMM - Env2\n(structure correction) 
##                                 2250                                 2250 
##                                  RDA         pRDA\n(structure correction) 
##                                 2250                                 2250
tapply(comparemethods.FDR$FDR,comparemethods.AUC$methodtype, function(x){sum(is.na(x))})
##                       Cor(p, Temp.) LFMM - Temp\n(structure correction) 
##                                 266                                 248 
##                        Cor(p, Env2) LFMM - Env2\n(structure correction) 
##                                 248                                 210 
##                                 RDA        pRDA\n(structure correction) 
##                                 204                                 246
g2<- ggplot(comparemethods.FDR, aes(x=as.factor(methodtype), y=FDR)) + geom_boxplot(color="grey", fill=rep(c("darkblue", "cornflowerblue"),3)) + ggtheme + xlab("method") + ylab("FDR\n(better <<--->> worse)") + scale_fill_viridis(option="turbo", discrete=TRUE) + theme(legend.position = "none") + theme( axis.text.x=element_text(angle=60, vjust=1, hjust=1, size = 10)) + ggtitle("A")
g2
## Warning: Removed 1422 rows containing non-finite values (stat_boxplot).

# There are more NAs because FDR has NAs for cases with no true positives (no power)

Compare methods POWER

Ideally, we would like power to be the same after correcting for pop structure as before we correct.

#Check for NAs in temperature models
  sum(is.na(final.df$cor_TPR_temp))
## [1] 0
  sum(is.na(final.df$LEA3.2_lfmm2_TPR_temp))
## [1] 0
# Check for NAs in salinity model
  sum(is.na(final.df$cor_TPR_sal)) #450 expected
## [1] 450
  sum(is.na(final.df$LEA3.2_lfmm2_TPR_sal))
## [1] 450
#Check for NAs in RDA model
  sum(is.na(final.df$RDA_TPR))
## [1] 0
  sum(is.na(final.df$RDA_TPR))
## [1] 0
# reorganize data for plotting
comparemethods.TPR <- gather(final.df, key=method, value=TPR, cor_TPR_temp, LEA3.2_lfmm2_TPR_temp, RDA_TPR, RDA_TPR_corr, cor_TPR_sal, LEA3.2_lfmm2_TPR_sal)

comparemethods.TPR <- comparemethods.TPR[order(comparemethods.TPR$seed),]
tail(comparemethods.TPR)
##          seed
## 2250  1233343
## 4500  1233343
## 6750  1233343
## 9000  1233343
## 11250 1233343
## 13500 1233343
##                                                                      level reps
## 2250  oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
## 4500  oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
## 6750  oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
## 9000  oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
## 11250 oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
## 13500 oliogenic_2-trait-pleiotropy-unequal-S__SS-Mtn_N-variable_m-variable   10
##                                         arch                   demog_name
## 2250  oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
## 4500  oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
## 6750  oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
## 9000  oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
## 11250 oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
## 13500 oliogenic_2-trait-pleiotropy-unequal-S SS-Mtn_N-variable_m-variable
##              demog_level_sub demog_level MIG_x MIG_y xcline ycline demog
## 2250  N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
## 4500  N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
## 6750  N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
## 9000  N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
## 11250 N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
## 13500 N variable\nm variable      SS-Mtn  0.03  0.03      V linear    SS
##       METAPOP_SIDE_x METAPOP_SIDE_y Nequal isVariableM MIG_breaks
## 2250              10             10      3           1          0
## 4500              10             10      3           1          0
## 6750              10             10      3           1          0
## 9000              10             10      3           1          0
## 11250             10             10      3           1          0
## 13500             10             10      3           1          0
##                        arch_level_sub arch_level MU_base MU_QTL_proportion
## 2250  2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
## 4500  2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
## 6750  2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
## 9000  2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
## 11250 2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
## 13500 2 traits\npleiotropy\nunequal S oligogenic   1e-07             0.001
##       SIGMA_QTN_1 SIGMA_QTN_2 SIGMA_K_1 SIGMA_K_2 N_traits ispleiotropy
## 2250          0.4         0.4       0.5         4        2   Pleiotropy
## 4500          0.4         0.4       0.5         4        2   Pleiotropy
## 6750          0.4         0.4       0.5         4        2   Pleiotropy
## 9000          0.4         0.4       0.5         4        2   Pleiotropy
## 11250         0.4         0.4       0.5         4        2   Pleiotropy
## 13500         0.4         0.4       0.5         4        2   Pleiotropy
##       n_samp_tot n_samp_per_pop sd_fitness_among_inds sd_fitness_among_pops
## 2250        1000             10             0.1193353             0.0675856
## 4500        1000             10             0.1193353             0.0675856
## 6750        1000             10             0.1193353             0.0675856
## 9000        1000             10             0.1193353             0.0675856
## 11250       1000             10             0.1193353             0.0675856
## 13500       1000             10             0.1193353             0.0675856
##       final_LA K   Bonf_alpha numCausalLowMAFsample all_corr_phen_temp
## 2250  0.361984 1 6.179706e-06                     0          0.8163458
## 4500  0.361984 1 6.179706e-06                     0          0.8163458
## 6750  0.361984 1 6.179706e-06                     0          0.8163458
## 9000  0.361984 1 6.179706e-06                     0          0.8163458
## 11250 0.361984 1 6.179706e-06                     0          0.8163458
## 13500 0.361984 1 6.179706e-06                     0          0.8163458
##       subsamp_corr_phen_temp all_corr_phen_sal subsamp_corr_phen_sal
## 2250               0.6347974          0.884965             0.7608153
## 4500               0.6347974          0.884965             0.7608153
## 6750               0.6347974          0.884965             0.7608153
## 9000               0.6347974          0.884965             0.7608153
## 11250              0.6347974          0.884965             0.7608153
## 13500              0.6347974          0.884965             0.7608153
##       num_causal_prefilter num_causal_postfilter num_non_causal
## 2250                    12                     8           8083
## 4500                    12                     8           8083
## 6750                    12                     8           8083
## 9000                    12                     8           8083
## 11250                   12                     8           8083
## 13500                   12                     8           8083
##       num_neut_prefilter num_neut_postfilter num_neut_neutralgenome
## 2250                8197                8197                   3947
## 4500                8197                8197                   3947
## 6750                8197                8197                   3947
## 9000                8197                8197                   3947
## 11250               8197                8197                   3947
## 13500               8197                8197                   3947
##       num_causal_temp num_causal_sal num_multiallelic   meanFst va_temp_total
## 2250                8              8                0 0.1737941    0.08556485
## 4500                8              8                0 0.1737941    0.08556485
## 6750                8              8                0 0.1737941    0.08556485
## 9000                8              8                0 0.1737941    0.08556485
## 11250               8              8                0 0.1737941    0.08556485
## 13500               8              8                0 0.1737941    0.08556485
##       va_sal_total Va_temp_sample Va_sal_sample nSNPs median_causal_temp_cor
## 2250      0.105924     0.08049695    0.09935857  8091              0.3033895
## 4500      0.105924     0.08049695    0.09935857  8091              0.3033895
## 6750      0.105924     0.08049695    0.09935857  8091              0.3033895
## 9000      0.105924     0.08049695    0.09935857  8091              0.3033895
## 11250     0.105924     0.08049695    0.09935857  8091              0.3033895
## 13500     0.105924     0.08049695    0.09935857  8091              0.3033895
##       median_causal_sal_cor median_neut_temp_cor median_neut_sal_cor
## 2250              0.3424647             0.248889           0.1358742
## 4500              0.3424647             0.248889           0.1358742
## 6750              0.3424647             0.248889           0.1358742
## 9000              0.3424647             0.248889           0.1358742
## 11250             0.3424647             0.248889           0.1358742
## 13500             0.3424647             0.248889           0.1358742
##       cor_VA_temp_prop cor_VA_sal_prop cor_FDR_allSNPs_temp
## 2250         0.3901235       0.8777962            0.9987903
## 4500         0.3901235       0.8777962            0.9987903
## 6750         0.3901235       0.8777962            0.9987903
## 9000         0.3901235       0.8777962            0.9987903
## 11250        0.3901235       0.8777962            0.9987903
## 13500        0.3901235       0.8777962            0.9987903
##       cor_FDR_neutSNPs_temp cor_FDR_allSNPs_sal cor_FDR_neutSNPs_sal
## 2250              0.9974958           0.9913043             0.974359
## 4500              0.9974958           0.9913043             0.974359
## 6750              0.9974958           0.9913043             0.974359
## 9000              0.9974958           0.9913043             0.974359
## 11250             0.9974958           0.9913043             0.974359
## 13500             0.9974958           0.9913043             0.974359
##       num_causal_sig_temp_corr num_causal_sig_sal_corr
## 2250                         3                       4
## 4500                         3                       4
## 6750                         3                       4
## 9000                         3                       4
## 11250                        3                       4
## 13500                        3                       4
##       num_notCausal_sig_temp_corr num_notCausal_sig_sal_corr
## 2250                         2477                        456
## 4500                         2477                        456
## 6750                         2477                        456
## 9000                         2477                        456
## 11250                        2477                        456
## 13500                        2477                        456
##       num_neut_sig_temp_corr num_neut_sig_sal_corr cor_AUCPR_temp_allSNPs
## 2250                    1195                   152            0.001387016
## 4500                    1195                   152            0.001387016
## 6750                    1195                   152            0.001387016
## 9000                    1195                   152            0.001387016
## 11250                   1195                   152            0.001387016
## 13500                   1195                   152            0.001387016
##       cor_AUCPR_temp_neutSNPs cor_AUCPR_sal_allSNPs cor_AUCPR_sal_neutSNPs
## 2250              0.002938006            0.02439708              0.2860155
## 4500              0.002938006            0.02439708              0.2860155
## 6750              0.002938006            0.02439708              0.2860155
## 9000              0.002938006            0.02439708              0.2860155
## 11250             0.002938006            0.02439708              0.2860155
## 13500             0.002938006            0.02439708              0.2860155
##       cor_af_temp_noutliers cor_af_sal_noutliers cor_FPR_temp_neutSNPs
## 2250                   2480                  460             0.3027616
## 4500                   2480                  460             0.3027616
## 6750                   2480                  460             0.3027616
## 9000                   2480                  460             0.3027616
## 11250                  2480                  460             0.3027616
## 13500                  2480                  460             0.3027616
##       cor_FPR_sal_neutSNPs LEA3.2_lfmm2_Va_temp_prop LEA3.2_lfmm2_Va_sal_prop
## 2250            0.03851026                         0                0.8777962
## 4500            0.03851026                         0                0.8777962
## 6750            0.03851026                         0                0.8777962
## 9000            0.03851026                         0                0.8777962
## 11250           0.03851026                         0                0.8777962
## 13500           0.03851026                         0                0.8777962
##       LEA3.2_lfmm2_FDR_allSNPs_temp LEA3.2_lfmm2_FDR_allSNPs_sal
## 2250                             NA                    0.9090909
## 4500                             NA                    0.9090909
## 6750                             NA                    0.9090909
## 9000                             NA                    0.9090909
## 11250                            NA                    0.9090909
## 13500                            NA                    0.9090909
##       LEA3.2_lfmm2_FDR_neutSNPs_temp LEA3.2_lfmm2_FDR_neutSNPs_sal
## 2250                              NA                             0
## 4500                              NA                             0
## 6750                              NA                             0
## 9000                              NA                             0
## 11250                             NA                             0
## 13500                             NA                             0
##       LEA3.2_lfmm2_AUCPR_temp_allSNPs LEA3.2_lfmm2_AUCPR_temp_neutSNPs
## 2250                        0.2117759                        0.5088647
## 4500                        0.2117759                        0.5088647
## 6750                        0.2117759                        0.5088647
## 9000                        0.2117759                        0.5088647
## 11250                       0.2117759                        0.5088647
## 13500                       0.2117759                        0.5088647
##       LEA3.2_lfmm2_AUCPR_sal_allSNPs LEA3.2_lfmm2_AUCPR_sal_neutSNPs
## 2250                       0.2117759                       0.5088647
## 4500                       0.2117759                       0.5088647
## 6750                       0.2117759                       0.5088647
## 9000                       0.2117759                       0.5088647
## 11250                      0.2117759                       0.5088647
## 13500                      0.2117759                       0.5088647
##       LEA3.2_lfmm2_mlog10P_tempenv_noutliers
## 2250                                       0
## 4500                                       0
## 6750                                       0
## 9000                                       0
## 11250                                      0
## 13500                                      0
##       LEA3.2_lfmm2_mlog10P_salenv_noutliers LEA3.2_lfmm2_num_causal_sig_temp
## 2250                                     44                                0
## 4500                                     44                                0
## 6750                                     44                                0
## 9000                                     44                                0
## 11250                                    44                                0
## 13500                                    44                                0
##       LEA3.2_lfmm2_num_neut_sig_temp LEA3.2_lfmm2_num_causal_sig_sal
## 2250                               0                               4
## 4500                               0                               4
## 6750                               0                               4
## 9000                               0                               4
## 11250                              0                               4
## 13500                              0                               4
##       LEA3.2_lfmm2_num_neut_sig_sal LEA3.2_lfmm2_FPR_neutSNPs_temp
## 2250                              0                              0
## 4500                              0                              0
## 6750                              0                              0
## 9000                              0                              0
## 11250                             0                              0
## 13500                             0                              0
##       LEA3.2_lfmm2_FPR_neutSNPs_sal RDA1_propvar RDA2_propvar RDA1_propvar_corr
## 2250                              0        0.739        0.261             0.673
## 4500                              0        0.739        0.261             0.673
## 6750                              0        0.739        0.261             0.673
## 9000                              0        0.739        0.261             0.673
## 11250                             0        0.739        0.261             0.673
## 13500                             0        0.739        0.261             0.673
##       RDA2_propvar_corr RDA1_temp_cor RDA1_sal_cor RDA2_temp_cor RDA2_sal_cor
## 2250              0.327     0.9800515    0.1987435    -0.1987435    0.9800515
## 4500              0.327     0.9800515    0.1987435    -0.1987435    0.9800515
## 6750              0.327     0.9800515    0.1987435    -0.1987435    0.9800515
## 9000              0.327     0.9800515    0.1987435    -0.1987435    0.9800515
## 11250             0.327     0.9800515    0.1987435    -0.1987435    0.9800515
## 13500             0.327     0.9800515    0.1987435    -0.1987435    0.9800515
##       RDA_Va_temp_prop RDA_Va_temp_prop_corr RDA_Va_sal_prop
## 2250         0.8073374             0.8955353       0.8777962
## 4500         0.8073374             0.8955353       0.8777962
## 6750         0.8073374             0.8955353       0.8777962
## 9000         0.8073374             0.8955353       0.8777962
## 11250        0.8073374             0.8955353       0.8777962
## 13500        0.8073374             0.8955353       0.8777962
##       RDA_Va_sal_prop_corr RDA_FDR_allSNPs RDA_FDR_allSNPs_corr
## 2250             0.9096928        0.983871            0.9814815
## 4500             0.9096928        0.983871            0.9814815
## 6750             0.9096928        0.983871            0.9814815
## 9000             0.9096928        0.983871            0.9814815
## 11250            0.9096928        0.983871            0.9814815
## 13500            0.9096928        0.983871            0.9814815
##       num_RDA_sig_causal num_RDA_sig_neutral num_RDA_sig_causal_corr
## 2250                   4                  62                       5
## 4500                   4                  62                       5
## 6750                   4                  62                       5
## 9000                   4                  62                       5
## 11250                  4                  62                       5
## 13500                  4                  62                       5
##       num_RDA_sig_neutral_corr RDA_FDR_neutSNPs RDA_FDR_neutSNPs_corr
## 2250                        92        0.9393939             0.9484536
## 4500                        92        0.9393939             0.9484536
## 6750                        92        0.9393939             0.9484536
## 9000                        92        0.9393939             0.9484536
## 11250                       92        0.9393939             0.9484536
## 13500                       92        0.9393939             0.9484536
##       RDA_AUCPR_allSNPs RDA_AUCPR_neutSNPs RDA_AUCPR_neutSNPs_corr
## 2250           0.203218          0.5029961                0.332056
## 4500           0.203218          0.5029961                0.332056
## 6750           0.203218          0.5029961                0.332056
## 9000           0.203218          0.5029961                0.332056
## 11250          0.203218          0.5029961                0.332056
## 13500          0.203218          0.5029961                0.332056
##       RDA_FPR_neutSNPs RDA_FPR_neutSNPs_corr RDA_RDAmutpred_cor_tempEffect
## 2250        0.01570813            0.02330884                           0.5
## 4500        0.01570813            0.02330884                           0.5
## 6750        0.01570813            0.02330884                           0.5
## 9000        0.01570813            0.02330884                           0.5
## 11250       0.01570813            0.02330884                           0.5
## 13500       0.01570813            0.02330884                           0.5
##       RDA_RDAmutpred_cor_salEffect RDA_absRDAmutpred_cor_tempVa
## 2250                     0.2857143                   0.02069674
## 4500                     0.2857143                   0.02069674
## 6750                     0.2857143                   0.02069674
## 9000                     0.2857143                   0.02069674
## 11250                    0.2857143                   0.02069674
## 13500                    0.2857143                   0.02069674
##       RDA_absRDAmutpred_cor_salVa RDA_RDAmutpred_cor_tempEffect_structcorr
## 2250                   0.02400657                                0.2752112
## 4500                   0.02400657                                0.2752112
## 6750                   0.02400657                                0.2752112
## 9000                   0.02400657                                0.2752112
## 11250                  0.02400657                                0.2752112
## 13500                  0.02400657                                0.2752112
##       RDA_RDAmutpred_cor_salEffect_structcorr
## 2250                                0.6602084
## 4500                                0.6602084
## 6750                                0.6602084
## 9000                                0.6602084
## 11250                               0.6602084
## 13500                               0.6602084
##       RDA_absRDAmutpred_cor_tempVa_structcorr
## 2250                               0.08556552
## 4500                               0.08556552
## 6750                               0.08556552
## 9000                               0.08556552
## 11250                              0.08556552
## 13500                              0.08556552
##       RDA_absRDAmutpred_cor_salVa_structcorr
## 2250                               0.1153435
## 4500                               0.1153435
## 6750                               0.1153435
## 9000                               0.1153435
## 11250                              0.1153435
## 13500                              0.1153435
##       RDA_cor_RDA20000temppredict_tempPhen RDA_cor_RDA20000salpredict_salPhen
## 2250                             0.5661217                          0.6653819
## 4500                             0.5661217                          0.6653819
## 6750                             0.5661217                          0.6653819
## 9000                             0.5661217                          0.6653819
## 11250                            0.5661217                          0.6653819
## 13500                            0.5661217                          0.6653819
##       RDA_cor_RDA20000temppredict_tempPhen_structcorr
## 2250                                         0.238542
## 4500                                         0.238542
## 6750                                         0.238542
## 9000                                         0.238542
## 11250                                        0.238542
## 13500                                        0.238542
##       RDA_cor_RDA20000salpredict_salPhen_structcorr cor_PC1_temp cor_PC1_sal
## 2250                                      0.6262283    0.7832223  0.09915203
## 4500                                      0.6262283    0.7832223  0.09915203
## 6750                                      0.6262283    0.7832223  0.09915203
## 9000                                      0.6262283    0.7832223  0.09915203
## 11250                                     0.6262283    0.7832223  0.09915203
## 13500                                     0.6262283    0.7832223  0.09915203
##       cor_PC2_temp cor_PC2_sal cor_LFMMU1_temp cor_LFMMU1_sal cor_LFMMU2_temp
## 2250    -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
## 4500    -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
## 6750    -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
## 9000    -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
## 11250   -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
## 13500   -0.4132312  -0.2945365       0.3684028     -0.0665779              NA
##       cor_LFMMU2_sal cor_PC1_LFMMU1_temp cor_PC1_LFMMU1_sal cor_PC2_LFMMU1_temp
## 2250              NA           0.8090855         -0.9986383           0.5807664
## 4500              NA           0.8090855         -0.9986383           0.5807664
## 6750              NA           0.8090855         -0.9986383           0.5807664
## 9000              NA           0.8090855         -0.9986383           0.5807664
## 11250             NA           0.8090855         -0.9986383           0.5807664
## 13500             NA           0.8090855         -0.9986383           0.5807664
##       cor_PC2_LFMMU1_sal gwas_TPR_sal gwas_TPR_temp gwas_FDR_sal_neutbase
## 2250         -0.02590842         0.75         0.875              0.997544
## 4500         -0.02590842         0.75         0.875              0.997544
## 6750         -0.02590842         0.75         0.875              0.997544
## 9000         -0.02590842         0.75         0.875              0.997544
## 11250        -0.02590842         0.75         0.875              0.997544
## 13500        -0.02590842         0.75         0.875              0.997544
##       gwas_FDR_temp_neutbase clinalparadigm_sal_proptop5GWASclines
## 2250                0.996434                             0.5333333
## 4500                0.996434                             0.5333333
## 6750                0.996434                             0.5333333
## 9000                0.996434                             0.5333333
## 11250               0.996434                             0.5333333
## 13500               0.996434                             0.5333333
##       clinalparadigm_temp_proptop5GWASclines
## 2250                               0.2074074
## 4500                               0.2074074
## 6750                               0.2074074
## 9000                               0.2074074
## 11250                              0.2074074
## 13500                              0.2074074
##       clinalparadigm_sal_propsigGWASclines
## 2250                            0.09349593
## 4500                            0.09349593
## 6750                            0.09349593
## 9000                            0.09349593
## 11250                           0.09349593
## 13500                           0.09349593
##       clinalparadigm_temp_propsigGWASclines N_traits2                method
## 2250                              0.2850657  2 Traits          cor_TPR_temp
## 4500                              0.2850657  2 Traits LEA3.2_lfmm2_TPR_temp
## 6750                              0.2850657  2 Traits               RDA_TPR
## 9000                              0.2850657  2 Traits          RDA_TPR_corr
## 11250                             0.2850657  2 Traits           cor_TPR_sal
## 13500                             0.2850657  2 Traits  LEA3.2_lfmm2_TPR_sal
##         TPR
## 2250  0.375
## 4500  0.000
## 6750  0.500
## 9000  0.625
## 11250 0.500
## 13500 0.500
comparemethods.TPR$methodtype <- factor(comparemethods.TPR$method)

levels(comparemethods.TPR$methodtype)
## [1] "cor_TPR_sal"           "cor_TPR_temp"          "LEA3.2_lfmm2_TPR_sal" 
## [4] "LEA3.2_lfmm2_TPR_temp" "RDA_TPR"               "RDA_TPR_corr"
comparemethods.TPR$methodtype <- revalue(comparemethods.TPR$methodtype,
                                         c("cor_TPR_sal"="Cor(p, Env2)", 
                                           "cor_TPR_temp"= "Cor(p, Temp.)",  
                                           "LEA3.2_lfmm2_TPR_sal" = "LFMM - Env2\n(structure correction)",
                                           "LEA3.2_lfmm2_TPR_temp" = "LFMM - Temp.\n(structure correction)",
                                           "RDA_TPR"  = "RDA"   ,        
                                           "RDA_TPR_corr" = "pRDA\n(structure correction)"  ))

comparemethods.TPR$methodtype <- factor(comparemethods.TPR$methodtype,
                                        levels = c("Cor(p, Temp.)",
                                                   "LFMM - Temp.\n(structure correction)",
                                                   "Cor(p, Env2)",
                                                   "LFMM - Env2\n(structure correction)",
                                                   "RDA",
                                                    "pRDA\n(structure correction)"),
                                        ordered=TRUE)

table(comparemethods.TPR$methodtype)  
## 
##                        Cor(p, Temp.) LFMM - Temp.\n(structure correction) 
##                                 2250                                 2250 
##                         Cor(p, Env2)  LFMM - Env2\n(structure correction) 
##                                 2250                                 2250 
##                                  RDA         pRDA\n(structure correction) 
##                                 2250                                 2250
g3<- ggplot(comparemethods.TPR, aes(x=as.factor(methodtype), y=TPR)) + geom_boxplot(color="grey", fill=rep(c("darkblue", "cornflowerblue"),3)) + ggtheme + xlab("method") + ylab("TPR\n(worse <<--->> better)") + scale_fill_viridis(option="turbo", discrete=TRUE) + theme(legend.position = "none") + theme( axis.text.x=element_text(angle=60, vjust=1, hjust=1, size = 10)) + ggtitle("B")
g3
## Warning: Removed 900 rows containing non-finite values (stat_boxplot).

#pdf(paste0(outputs,"AUC-PR_FDR_TPR.pdf"), width=5, height=9)
#grid.arrange(g+ theme( axis.text.x = element_blank(), axis.title.x=element_blank()),
#             g2+ theme( axis.text.x = element_blank(), axis.title.x=element_blank()),
#             g3,
#             layout_matrix=matrix(c(1,1,1,2,2,2,3,3,3,3,3), nrow=11))
#dev.off()

pdf(paste0(outputs,"GEAs-AUC.pdf"), width=5, height=4)
g
## Warning: Removed 900 rows containing non-finite values (stat_boxplot).
dev.off()
## svg 
##   2

LFMM - TPR vs STRUCTURE

### THIS IS THE GRAPH
# Fix colors for arch_level_sub, 
# rename legend and make it taller, 
# reorder the legend levels
# For the 2nd legend, there is no "1 trait sims"

k1p <- ggplot(final.df) + geom_point(aes(x=abs(cor_LFMMU1_temp),y=LEA3.2_lfmm2_TPR_temp, color=arch_level_sub, shape=arch_level_sub)) + ggtheme + 
  xlab("|Cor(LFMM U1, Deme Temperature)|") + 
  ylab("TPR (LFMM Temp. Model)") +  
  scale_fill_viridis(option="magma", discrete=TRUE) +  
  scale_color_viridis(option="magma", discrete=TRUE, begin=0, end=0.9) + 
  geom_smooth(aes(x=abs(cor_LFMMU1_temp),y=LEA3.2_lfmm2_TPR_temp, color=arch_level_sub), alpha=0.2, method="lm", size=0.5) + ggtitle("A) Temp model") +
  ylim(0,1)  +xlim(0,1) + facet_wrap(~arch_level) + theme(legend.position = "none")
k1p # was not easy to change the color scheme here + scale_fill_viridis(option="mako", discrete=TRUE)
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing missing values (geom_smooth).

k2p <- ggplot(final.df) + 
  geom_point(aes(x=abs(cor_LFMMU1_sal),y=LEA3.2_lfmm2_TPR_sal, color=arch_level_sub, shape=arch_level_sub)) + ggtheme + 
  xlab("|Cor(LFMM U1, Deme Env2)|") + ylab("TPR (LFMM Env2 Model)") +
  geom_smooth(aes(x=abs(cor_LFMMU1_sal),y=LEA3.2_lfmm2_TPR_sal, color=arch_level_sub), alpha=0.2, method="lm", size=0.5) + 
  ylim(0,1) +xlim(0,1) + ggtitle("B) Env2 model") +
  scale_fill_viridis(option="magma", discrete=TRUE) + 
  scale_color_viridis(option="magma", discrete=TRUE, begin=0, end=0.9)  + 
  facet_wrap(~arch_level) + theme(legend.position = "bottom") 
k2p
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 450 rows containing non-finite values (stat_smooth).
## Warning: Removed 450 rows containing missing values (geom_point).
## Warning: Removed 32 rows containing missing values (geom_smooth).

lm_plot <- summary(lm(c(final.df$LEA3.2_lfmm2_TPR_temp,final.df$LEA3.2_lfmm2_TPR_sal)~
             c(abs(final.df$cor_LFMMU1_temp), abs(final.df$cor_LFMMU1_sal))
           ))
lm_plot
## 
## Call:
## lm(formula = c(final.df$LEA3.2_lfmm2_TPR_temp, final.df$LEA3.2_lfmm2_TPR_sal) ~ 
##     c(abs(final.df$cor_LFMMU1_temp), abs(final.df$cor_LFMMU1_sal)))
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.2668 -0.2453 -0.1162  0.1416  0.8827 
## 
## Coefficients:
##                                                                 Estimate
## (Intercept)                                                     0.266811
## c(abs(final.df$cor_LFMMU1_temp), abs(final.df$cor_LFMMU1_sal)) -0.237447
##                                                                Std. Error
## (Intercept)                                                      0.005533
## c(abs(final.df$cor_LFMMU1_temp), abs(final.df$cor_LFMMU1_sal))   0.032261
##                                                                t value Pr(>|t|)
## (Intercept)                                                      48.22  < 2e-16
## c(abs(final.df$cor_LFMMU1_temp), abs(final.df$cor_LFMMU1_sal))   -7.36 2.21e-13
##                                                                   
## (Intercept)                                                    ***
## c(abs(final.df$cor_LFMMU1_temp), abs(final.df$cor_LFMMU1_sal)) ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3058 on 4048 degrees of freedom
##   (450 observations deleted due to missingness)
## Multiple R-squared:  0.01321,    Adjusted R-squared:  0.01296 
## F-statistic: 54.17 on 1 and 4048 DF,  p-value: 2.212e-13
(slope=lm_plot$coefficients[2,1])
## [1] -0.2374471
(int <- lm_plot$coefficients[1,1])
## [1] 0.266811
### Create a plot showing overall pattern   
mydf <- data.frame(y=c(final.df$LEA3.2_lfmm2_TPR_temp,final.df$LEA3.2_lfmm2_TPR_sal) ,
                   x = c(abs(final.df$cor_LFMMU1_temp), abs(final.df$cor_LFMMU1_sal)))

k3p <- ggplot(mydf) + geom_point(aes(x,y), alpha=0.5, color="tomato1") + 
  ggtheme + 
  xlab("|Cor(LFMM U1, Deme Environment)|") + 
  ylab("TPR (LFMM)") +  
  geom_smooth(aes(x,y), method="lm", size=0.5, color="black") + 
  ggtitle("C") +
  ylim(0,1)  +xlim(0,1) + theme(legend.position = "none")
k3p
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 450 rows containing non-finite values (stat_smooth).
## Warning: Removed 450 rows containing missing values (geom_point).

pdf(paste0(outputs,"LFMM-TPRvsStructure.pdf"), width=8, height=8)
grid.arrange(k1p,k2p, nrow=2)
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing missing values (geom_smooth).
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 450 rows containing non-finite values (stat_smooth).
## Warning: Removed 450 rows containing missing values (geom_point).
## Warning: Removed 32 rows containing missing values (geom_smooth).
# 450 missing values expected here
dev.off()
## svg 
##   2
pdf(paste0(outputs,"GEA_results.pdf"), width=5, height=9)
  grid.arrange(
  g2+ theme( axis.text.x = element_blank(), axis.title.x=element_blank()),
  g3,
  k3p,
     layout_matrix=matrix(c(1,1,1,2,2,2,2,2,3,3,3,3), nrow=12)
  )
## Warning: Removed 1422 rows containing non-finite values (stat_boxplot).
## Warning: Removed 900 rows containing non-finite values (stat_boxplot).
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 450 rows containing non-finite values (stat_smooth).
## Warning: Removed 450 rows containing missing values (geom_point).
dev.off()
## svg 
##   2

RDA checks

par(mfrow=c(2,2))
sum(is.na(final.df$RDA_RDAmutpred_cor_tempEffect))
## [1] 0
sum(is.na(final.df$RDA_RDAmutpred_cor_salEffect)) #450 expected
## [1] 450
sum(is.na(final.df$RDA_cor_RDA20000temppredict_tempPhen))
## [1] 0
sum(is.na(final.df$RDA_cor_RDA20000salpredict_salPhen))  #450 expected
## [1] 450
# Seeds with really bad performance (no structure correction)
final.df$seed[which(final.df$RDA_RDAmutpred_cor_tempEffect < 0)]
## [1] 1231305
final.df$seed[which(final.df$RDA_RDAmutpred_cor_salEffect < 0)]
## [1] 1231259 1231713 1231725 1232658 1233108 1233333
final.df$seed[which(final.df$RDA_cor_RDA20000temppredict_tempPhen < 0)]
## integer(0)
final.df$seed[which(final.df$RDA_cor_RDA20000salppredict_salPhen < 0)]
## integer(0)

Can redundancy analysis identify mutations with pleiotropic effects?

g1<- ggplot(final.df, aes(x=RDA_RDAmutpred_cor_tempEffect, fill=arch_level)) + geom_histogram(color="grey40", binwidth=0.05) + ggtheme + coord_cartesian(xlim = c(-1, 1)) + xlab("Cor(QTN effect on temp,\nRDA-predicted temp. effect)") + guides(fill=guide_legend(title="Genetic\nArchitecture")) + scale_fill_viridis(option="rocket", discrete=TRUE) + theme(legend.position = "none") + ggtitle("A) Temperature mutation effect")
g1 

g2 <- ggplot(final.df, aes(x=RDA_RDAmutpred_cor_salEffect, fill=arch_level)) + geom_histogram(color="grey40", binwidth=0.05) + ggtheme+ coord_cartesian(xlim = c(-1, 1))  + xlab("Cor(QTN effect on Env2,\nRDA-predicted Env2 effect)") + guides(fill=guide_legend(title="Genetic\nArchitecture")) + scale_fill_viridis(option="rocket", discrete=TRUE) + theme(legend.position="bottom") + ggtitle("B) Env2 mutation effect") 
g2
## Warning: Removed 450 rows containing non-finite values (stat_bin).

# removing 450 expected

  grid.arrange(g1, g2,
               layout_matrix = matrix(c(1,1,1,2,2,2,2), nrow=7))
## Warning: Removed 450 rows containing non-finite values (stat_bin).

# They show the same pattern, so combine for analysis:
forhist <- gather(final.df, key=env, value=Accuracy, RDA_RDAmutpred_cor_tempEffect, RDA_RDAmutpred_cor_salEffect)

g3 <- ggplot(forhist, aes(x=Accuracy, fill=arch_level)) + geom_histogram(color="grey40", binwidth=0.05) + ggtheme + coord_cartesian(xlim = c(-1, 1))  + xlab("Accuracy\nCor(evolved effect size,\n predicted effect size from RDA)") + guides(fill=guide_legend(title="Genetic\nArchitecture")) + scale_fill_viridis(option="rocket", discrete=TRUE) +  ggtitle("D) Accuracy of RDA prediction \n     (QTN effect size, no structure correction)") 
g3
## Warning: Removed 450 rows containing non-finite values (stat_bin).

# 450 missing values expected

Same analysis as above, but with structure correction

g1sc<- ggplot(final.df, aes(x=RDA_RDAmutpred_cor_tempEffect_structcorr, fill=arch_level)) + geom_histogram(color="grey40", binwidth=0.05) + ggtheme + coord_cartesian(xlim = c(-1, 1))  + xlab("Cor(QTN effect on temp,\nRDA-predicted temp. effect)") + guides(fill=guide_legend(title="Genetic\nArchitecture")) + scale_fill_viridis(option="rocket", discrete=TRUE) + theme(legend.position = "none") + ggtitle("A) Temperature mutation effect with structure correction")
g1sc

g2sc <- ggplot(final.df, aes(x=RDA_RDAmutpred_cor_salEffect_structcorr, fill=arch_level)) + geom_histogram(color="grey40", binwidth=0.05) + ggtheme +  coord_cartesian(xlim = c(-1, 1))  + xlab("Cor(QTN effect on Env2,\nRDA-predicted Env2 effect)") + guides(fill=guide_legend(title="Genetic\nArchitecture")) + scale_fill_viridis(option="rocket", discrete=TRUE) + theme(legend.position="bottom") + ggtitle("B) Env2 mutation effect with structure correction") 
g2sc
## Warning: Removed 450 rows containing non-finite values (stat_bin).

grid.arrange(g1sc, g2sc,
               layout_matrix = matrix(c(1,1,1,2,2,2,2), nrow=7))
## Warning: Removed 450 rows containing non-finite values (stat_bin).

Another way to view the structure correction - boxplot

library(plyr)
### Temp 
  
  #### Check for missing data
  sum(is.na(final.df$RDA_RDAmutpred_cor_tempEffect))
## [1] 0
  sum(is.na(final.df$RDA_RDAmutpred_cor_tempEffect_structcorr))
## [1] 0
  #### organize data
  RDA_mutpredict <- gather(final.df, key=structcorr, value=Accuracy, RDA_RDAmutpred_cor_tempEffect, RDA_RDAmutpred_cor_tempEffect_structcorr)
  
  RDA_mutpredict$demog_level <- factor(RDA_mutpredict$demog_level)
  RDA_mutpredict$structcorr <- factor(RDA_mutpredict$structcorr)
  RDA_mutpredict$structcorr <- revalue(RDA_mutpredict$structcorr,c( "RDA_RDAmutpred_cor_tempEffect" = "No (RDA)",                                                           "RDA_RDAmutpred_cor_tempEffect_structcorr" = "Yes (pRDA)"))
  levels(RDA_mutpredict$structcorr)
## [1] "No (RDA)"   "Yes (pRDA)"
  # check again for missing data
  sum(is.na(RDA_mutpredict$Accuracy))
## [1] 0
  n <- ggplot(RDA_mutpredict, aes(y=Accuracy,x=demog_level, fill=structcorr)) + geom_boxplot(color="grey40") + ggtheme  +  coord_cartesian(ylim = c(-1, 1))   + ylab("Accuracy of RDA prediction\n(worse <<----->> better)") + ggtitle("C) RDA prediction accuracy: QTN effect size on Temp.")  + guides(fill=guide_legend(title="Structure\nCorrection?")) + 
    theme(axis.text.x=element_blank()) + xlab("")
  # Cor(Mutation effect on Temp.,\nRDA-predicted Temp. effect)
  n

  # 450 rows


### Sal
  RDA_mutpredict_sal <- gather(final.df, key=structcorr, value=Accuracy, RDA_RDAmutpred_cor_salEffect, RDA_RDAmutpred_cor_salEffect_structcorr)
  
  RDA_mutpredict_sal$demog_level <- factor(RDA_mutpredict_sal$demog_level)
  RDA_mutpredict_sal$structcorr <- factor(RDA_mutpredict_sal$structcorr)
  RDA_mutpredict_sal$structcorr <- revalue(RDA_mutpredict_sal$structcorr,c( "RDA_RDAmutpred_cor_salEffect" = "No (RDA)",                                                           "RDA_RDAmutpred_cor_salEffect_structcorr" = "Yes (pRDA)"))
  levels(RDA_mutpredict$structcorr)
## [1] "No (RDA)"   "Yes (pRDA)"
  # check for NA values
    sum(is.na(RDA_mutpredict_sal$Accuracy))
## [1] 900
    # 900 expected (450 from each set combined to one data frame)
  
  o <- ggplot(RDA_mutpredict_sal, aes(y=Accuracy,x=demog_level, fill=structcorr)) + geom_boxplot(color="grey40") + ggtheme +  coord_cartesian(ylim = c(-1, 1))    +  ylab("Accuracy of RDA prediction \n(worse <<----->> better)") + ggtitle("D) RDA prediction accuracy: QTN effect size on Env2")  + guides(fill=guide_legend(title="Structure\nCorrection?"))  + xlab("Landscape")
  # "Cor(Mutation effect on Env2,\nRDA-predicted Env2 effect)"
  o
## Warning: Removed 900 rows containing non-finite values (stat_boxplot).

pdf(paste0(outputs,"RDA-Predict-Muts.pdf"), width=5.5, height=7)
  grid.arrange(g3, n,o)
## Warning: Removed 450 rows containing non-finite values (stat_bin).

## Warning: Removed 900 rows containing non-finite values (stat_boxplot).
dev.off()
## svg 
##   2
pdf(paste0(outputs,"RDA-Predict-Muts-nohist.pdf"), width=4, height=5.5)
  grid.arrange(n,o)
## Warning: Removed 900 rows containing non-finite values (stat_boxplot).
dev.off()
## svg 
##   2

What drives the population correction effect?

############
## Temp
############
## What drives the change in performance with structure correction?
final.df$change_temp_mut <- final.df$RDA_RDAmutpred_cor_tempEffect_structcorr - final.df$RDA_RDAmutpred_cor_tempEffect

summary(aov(final.df$change_temp_mut~final.df$cor_PC1_temp + final.df$cor_PC2_temp + 
              final.df$demog_level + final.df$demog_level_sub + final.df$arch_level))
##                            Df Sum Sq Mean Sq F value   Pr(>F)    
## final.df$cor_PC1_temp       1   0.00  0.0002   0.005 0.942064    
## final.df$cor_PC2_temp       1   0.43  0.4332  11.385 0.000753 ***
## final.df$demog_level        2   2.39  1.1972  31.465 3.34e-14 ***
## final.df$demog_level_sub    4   8.81  2.2021  57.878  < 2e-16 ***
## final.df$arch_level         2   3.20  1.5995  42.040  < 2e-16 ***
## Residuals                2239  85.19  0.0380                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
p1 <- ggplot(final.df) + 
  geom_point(aes(x=abs(cor_PC1_temp), y=change_temp_mut, color=demog_level, shape=demog_level_sub), alpha=0.5) + ggtheme + 
  ylab("Change in accuracy\nafter structure correction\n(worse <<------->> better)") + xlab("|Cor(Structure as PC1, Temp)|") + 
  guides(color=guide_legend(title="Landscape"), shape=guide_legend("Demography")) + ggtitle("A) Mutation effect on Temperature") +  coord_cartesian(ylim = c(-1, 1))   + 
  geom_smooth(aes(x=abs(cor_PC1_temp),y=change_temp_mut), color="tomato", method="loess", span=1)  + scale_fill_discrete(guide="none") + geom_hline(yintercept=0, color="black")
p1
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'

#####################
## Env 2 trait
#####################

## What drives the change in performance with structure correction?
final.df$change_sal_mut <- final.df$RDA_RDAmutpred_cor_salEffect_structcorr - final.df$RDA_RDAmutpred_cor_salEffect
summary(aov(final.df$change_sal_mut~final.df$cor_PC1_sal+ final.df$cor_PC2_sal + 
              final.df$demog_level + final.df$demog_level_sub + final.df$arch_level))
##                            Df Sum Sq Mean Sq F value   Pr(>F)    
## final.df$cor_PC1_sal        1   3.80   3.802 173.383  < 2e-16 ***
## final.df$cor_PC2_sal        1   0.00   0.002   0.111    0.739    
## final.df$demog_level        2  36.25  18.126 826.617  < 2e-16 ***
## final.df$demog_level_sub    4   4.43   1.107  50.473  < 2e-16 ***
## final.df$arch_level         2   1.16   0.582  26.540 4.38e-12 ***
## Residuals                1789  39.23   0.022                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 450 observations deleted due to missingness
p2 <- ggplot(final.df) + geom_point(aes(x=abs(cor_PC1_sal), y=change_sal_mut, color=demog_level, shape=demog_level_sub), alpha=0.5) + ggtheme + ylab("Change in accurcay\nafter structure correction\n(worse <<------->> better)") + xlab("|Cor(Structure as PC1, Env2)|") + guides(color=guide_legend(title="Landscape"), shape=guide_legend("Demography")) + ggtitle("B) Mutation effect on Env2")  +  coord_cartesian(ylim = c(-1, 1))   + 
  geom_smooth(aes(x=abs(cor_PC1_sal),y=change_sal_mut), method="loess", span=1, color="tomato") + scale_fill_discrete(guide="none") + geom_hline(yintercept=0, color="black")
p2
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 450 rows containing non-finite values (stat_smooth).
## Warning: Removed 450 rows containing missing values (geom_point).

pdf(paste0(outputs,"RDA-Predict-Muts-CovariateStructure.pdf"), width=6, height=7)
  grid.arrange(p1, p2)
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 450 rows containing non-finite values (stat_smooth).

## Warning: Removed 450 rows containing missing values (geom_point).
dev.off()
## svg 
##   2

Under what conditions can redundancy analysis predict an individual’s optimal environment, without knowledge of the genetic architecture of adaptation?

Visualize the effect of genetic architecture on phenotype prediction

forhist <- gather(final.df, key=env, value=Accuracy, RDA_cor_RDA20000temppredict_tempPhen, RDA_cor_RDA20000salpredict_salPhen) %>% filter(num_neut_postfilter>20000)

g4 <- ggplot(forhist, aes(x=Accuracy, fill=arch_level)) + geom_histogram(color="grey40", binwidth=0.05) + ggtheme +  coord_cartesian(xlim = c(-1, 1))   + xlab("Accuracy\nCor(evolved phenotype,\n predicted phenotype from RDA)") + guides(fill=guide_legend(title="Genetic\nArchitecture")) + scale_fill_viridis(option="rocket", discrete=TRUE) +  ggtitle("C) Accuracy of RDA prediction \n     (individual trait value,\n     no structure correction)") 
g4
## Warning: Removed 360 rows containing non-finite values (stat_bin).

Accuracy of RDA prediction maxed out by cor (phenotype, Env)

#Scatterplot

levels(final.df$demog_level_sub)
## [1] "N equal\nm constant"          "N equal\nm breaks"           
## [3] "N latitude cline\nm constant" "N central cline\nm constant" 
## [5] "N variable\nm variable"
forscatter <- filter(final.df, num_neut_postfilter>20000) %>% arrange(desc(demog_level_sub))
  
n1 <- ggplot(forscatter) +   geom_point(aes(x=subsamp_corr_phen_temp,
                   y=RDA_cor_RDA20000temppredict_tempPhen, bg=demog_level,
                       shape=demog_level), color="grey",alpha=0.7) + ylim(0,1) + xlim(0,1) +
     ggtheme + geom_abline(slope=1, color="grey") + 
  scale_shape_manual(values = c(21, 22, 23), name="Landscape") + guides(bg = "none") +
  xlab("Evolved phenotypic cline\nCor(Temp. phenotype, Deme Temp.)") +
  ylab("Prediction accuracy\nCor(RDA prediction,\nTemp. phenotype)") + ggtitle("A) Accuracy of RDA prediction\n     (Temp. trait, no structure correction)")
  
n1 

n2<-  ggplot(forscatter) +   geom_point(aes(x=subsamp_corr_phen_sal,
                   y=RDA_cor_RDA20000salpredict_salPhen, bg=demog_level,
                       shape=demog_level), alpha=0.7, color="grey") + ylim(0,1) + xlim(0,1) + 
     ggtheme + geom_abline(slope=1, color="grey") + 
  scale_shape_manual(values = c(21, 22, 23), name="Landscape") + guides(bg = "none") +
  xlab("Evolved phenotypic cline\nCor(Env2 phenotype, Deme Env2)") +
  ylab("Prediction accuracy\nCor(RDA prediction,\nEnv2 phenotype)")  +
  ggtitle("B) Accuracy of RDA prediction\n     (Env2 trait, no structure correction)")
n2  
## Warning: Removed 360 rows containing missing values (geom_point).

# missing values expected due to filtering

pdf(paste0(outputs,"RDA-Demog-scatter.pdf"), width=6, height=10)
  grid.arrange(g4,  n1,  n2, ncol=1)
## Warning: Removed 360 rows containing non-finite values (stat_bin).

## Warning: Removed 360 rows containing missing values (geom_point).
dev.off()
## svg 
##   2
pdf(paste0(outputs,"RDA-Demog-scatter-noHist.pdf"), width=4.5, height=7)
  grid.arrange(n1,  n2)
## Warning: Removed 360 rows containing missing values (geom_point).
dev.off()
## svg 
##   2
pdf(paste0(outputs,"RDA-Hists-PopMut.pdf"), width=5, height=7)
  grid.arrange(g4, g3)
## Warning: Removed 360 rows containing non-finite values (stat_bin).
## Warning: Removed 450 rows containing non-finite values (stat_bin).
dev.off()
## svg 
##   2

Effect of structure correction

# Reorganize data
RDA_indpredict <- gather(final.df, key=structcorr, value=Accuracy, RDA_cor_RDA20000temppredict_tempPhen, RDA_cor_RDA20000temppredict_tempPhen_structcorr)

RDA_indpredict$demog_level <- factor(RDA_indpredict$demog_level)
RDA_indpredict$structcorr <- factor(RDA_indpredict$structcorr)
RDA_indpredict$structcorr <- revalue(RDA_indpredict$structcorr,c( "RDA_cor_RDA20000temppredict_tempPhen" = "No (RDA)", "RDA_cor_RDA20000temppredict_tempPhen_structcorr" = "Yes (pRDA)"))
levels(RDA_indpredict$structcorr)
## [1] "No (RDA)"   "Yes (pRDA)"
n <- ggplot(RDA_indpredict, aes(y=Accuracy,x=demog_level, fill=structcorr)) + geom_boxplot(color="grey40") + ggtheme + ylim(-1,1) + ylab("Accuracy\nCor(evolved Temp. phenotype,\n predicted Temp. phenotype from RDA)") + ggtitle("A) Accuracy of RDA prediction\n      (Temp. phenotype)")  + guides(fill=guide_legend(title="Structure\nCorrection?")) + xlab("Landscape")
n

## Same as above for Env2 trait
RDA_indpredict_sal <- gather(final.df, key=structcorr, value=Accuracy, RDA_cor_RDA20000salpredict_salPhen, RDA_cor_RDA20000salpredict_salPhen_structcorr)

RDA_indpredict_sal$demog_level <- factor(RDA_indpredict_sal$demog_level)
RDA_indpredict_sal$structcorr <- factor(RDA_indpredict_sal$structcorr)
RDA_indpredict_sal$structcorr <- revalue(RDA_indpredict_sal$structcorr,c( "RDA_cor_RDA20000salpredict_salPhen" = "No (RDA)", "RDA_cor_RDA20000salpredict_salPhen_structcorr" = "Yes (pRDA)"))
levels(RDA_indpredict_sal$structcorr)
## [1] "No (RDA)"   "Yes (pRDA)"
o <- ggplot(RDA_indpredict_sal, aes(y=Accuracy,x=demog_level, fill=structcorr)) + geom_boxplot(color="grey40") + ggtheme + ylim(-1,1) + ylab("Accuracy\nCor(evolved Env2. phenotype,\n predicted Env2. phenotype from RDA)") + ggtitle("B) Accuracy of RDA prediction\n      (Env2. phenotype)")  + guides(fill=guide_legend(title="Structure\nCorrection?")) + xlab("Landscape")
o
## Warning: Removed 900 rows containing non-finite values (stat_boxplot).

# 900 missing values expected


pdf(paste0(outputs,"RDA-Predict-Phen-struct.pdf"), width=5, height=7)
  grid.arrange(n, o)
## Warning: Removed 900 rows containing non-finite values (stat_boxplot).
dev.off()
## svg 
##   2

Understand how correlation with PC affects structure correction

## Temp
## What drives the change in performance with structure correction?
final.df$change_temp <- final.df$RDA_cor_RDA20000temppredict_tempPhen_structcorr - final.df$RDA_cor_RDA20000temppredict_tempPhen

summary(aov(final.df$change_temp~final.df$cor_PC1_temp + final.df$cor_PC2_temp + 
              final.df$demog_level + final.df$demog_level_sub + final.df$arch_level))
##                            Df Sum Sq Mean Sq F value   Pr(>F)    
## final.df$cor_PC1_temp       1  4.453   4.453 413.204  < 2e-16 ***
## final.df$cor_PC2_temp       1  0.195   0.195  18.070 2.22e-05 ***
## final.df$demog_level        2  6.013   3.007 278.989  < 2e-16 ***
## final.df$demog_level_sub    4  9.961   2.490 231.062  < 2e-16 ***
## final.df$arch_level         2  0.032   0.016   1.489    0.226    
## Residuals                2239 24.129   0.011                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
p1 <- ggplot(final.df) + 
  geom_point(aes(x=abs(cor_PC1_temp), y=change_temp, color=demog_level, shape=demog_level_sub), alpha=0.5) + ggtheme + 
  ylab("Change in accuracy\nafter structure correction\n(worse <<------->> better)") + xlab("|Cor(Structure as PC1, Temp)|") + 
  guides(color=guide_legend(title="Landscape"), shape=guide_legend("Demography")) + ggtitle("A) Temperature Phenotype") + ylim(-1,1) + 
  geom_smooth(aes(x=abs(cor_PC1_temp),y=change_temp, color=demog_level, fill=demog_level), alpha=0.2, method="loess", span=1)  + scale_fill_discrete(guide="none")
p1
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).

#####################
## Env 2 trait
#####################

## What drives the change in performance with structure correction?
final.df$change_sal <- final.df$RDA_cor_RDA20000salpredict_salPhen_structcorr - final.df$RDA_cor_RDA20000salpredict_salPhen
summary(aov(final.df$change_sal~final.df$cor_PC1_sal+ final.df$cor_PC2_sal + 
              final.df$demog_level + final.df$demog_level_sub + final.df$arch_level))
##                            Df Sum Sq Mean Sq  F value  Pr(>F)    
## final.df$cor_PC1_sal        1  20.55   20.55 2509.144 < 2e-16 ***
## final.df$cor_PC2_sal        1   0.10    0.10   11.756 0.00062 ***
## final.df$demog_level        2 133.70   66.85 8160.706 < 2e-16 ***
## final.df$demog_level_sub    4   6.21    1.55  189.427 < 2e-16 ***
## final.df$arch_level         2   0.01    0.00    0.562 0.57034    
## Residuals                1789  14.66    0.01                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 450 observations deleted due to missingness
p2 <- ggplot(final.df) + geom_point(aes(x=abs(cor_PC1_sal), y=change_sal, color=demog_level, shape=demog_level_sub), alpha=0.5) + ggtheme + ylab("Change in accuracy\nafter structure correction\n(worse <<------->> better)") + xlab("|Cor(Structure as PC1, Env2)|") + guides(color=guide_legend(title="Landscape"), shape=guide_legend("Demography")) + ggtitle("B) Env2 Phenotype") + ylim(-1,1) + 
  geom_smooth(aes(x=abs(cor_PC1_sal),y=change_sal, color=demog_level, fill=demog_level), alpha=0.2, method="loess", span=1) + scale_fill_discrete(guide="none")
p2
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 450 rows containing non-finite values (stat_smooth).
## Warning: Removed 450 rows containing missing values (geom_point).

pdf(paste0(outputs,"RDA-Predict-Traits-CovariateStructure.pdf"), width=6, height=7)
  grid.arrange(p1, p2)
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 2 rows containing non-finite values (stat_smooth).
## Warning: Removed 2 rows containing missing values (geom_point).
## Warning: Using shapes for an ordinal variable is not advised
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 450 rows containing non-finite values (stat_smooth).
## Warning: Removed 450 rows containing missing values (geom_point).
dev.off()
## svg 
##   2
#hist(final.df$cor_RDA20000_RDloadings_tempPhen, xlim=c(0,1), breaks=seq(0,1,0.05))
#hist(final.df$cor_RDA20000_RDloadings_salPhen, xlim=c(0,1), breaks=seq(0,1,0.05))

Statistical models

length(levels(final.df$arch))
## [1] 15
# Stat models for temperature effect prediction
  tm_me <- summary(aov(RDA_RDAmutpred_cor_tempEffect~ subsamp_corr_phen_temp + demog_level + demog_level_sub + arch + demog_level*demog_level_sub*arch, data=final.df))
  tm_me
##                                    Df Sum Sq Mean Sq F value   Pr(>F)    
## subsamp_corr_phen_temp              1   2.42   2.423 228.140  < 2e-16 ***
## demog_level                         2   5.79   2.893 272.483  < 2e-16 ***
## demog_level_sub                     4   0.48   0.119  11.199 5.48e-09 ***
## arch                               14  58.93   4.209 396.406  < 2e-16 ***
## demog_level:demog_level_sub         8   0.14   0.017   1.631   0.1109    
## demog_level:arch                   28   1.29   0.046   4.343 3.68e-13 ***
## demog_level_sub:arch               56   1.59   0.028   2.667 5.82e-10 ***
## demog_level:demog_level_sub:arch  112   1.47   0.013   1.236   0.0515 .  
## Residuals                        2024  21.49   0.011                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  sm_me <- summary(aov(RDA_RDAmutpred_cor_salEffect~ subsamp_corr_phen_temp + demog_level + demog_level_sub + arch + demog_level*demog_level_sub*arch, data=final.df))
  sm_me
##                                    Df Sum Sq Mean Sq F value   Pr(>F)    
## subsamp_corr_phen_temp              1  0.867   0.867  60.947 1.05e-14 ***
## demog_level                         2  7.493   3.746 263.414  < 2e-16 ***
## demog_level_sub                     4  3.031   0.758  53.283  < 2e-16 ***
## arch                               11 23.549   2.141 150.526  < 2e-16 ***
## demog_level:demog_level_sub         8  1.386   0.173  12.177  < 2e-16 ***
## demog_level:arch                   22  6.739   0.306  21.536  < 2e-16 ***
## demog_level_sub:arch               44  1.603   0.036   2.561 1.28e-07 ***
## demog_level:demog_level_sub:arch   88  1.769   0.020   1.413  0.00822 ** 
## Residuals                        1619 23.026   0.014                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 450 observations deleted due to missingness
# STat models for phenotype prediction
tm_pp <- summary(aov(RDA_cor_RDA20000temppredict_tempPhen~ subsamp_corr_phen_temp + demog_level + demog_level_sub + arch + demog_level*demog_level_sub*arch, data=final.df))
tm_pp
##                                    Df Sum Sq Mean Sq   F value   Pr(>F)    
## subsamp_corr_phen_temp              1 14.407  14.407 59565.024  < 2e-16 ***
## demog_level                         2  0.009   0.005    19.303 4.96e-09 ***
## demog_level_sub                     4  0.384   0.096   396.873  < 2e-16 ***
## arch                               14  0.027   0.002     8.071  < 2e-16 ***
## demog_level:demog_level_sub         8  0.039   0.005    20.105  < 2e-16 ***
## demog_level:arch                   28  0.016   0.001     2.363 7.67e-05 ***
## demog_level_sub:arch               56  0.060   0.001     4.444  < 2e-16 ***
## demog_level:demog_level_sub:arch  112  0.034   0.000     1.248   0.0438 *  
## Residuals                        2024  0.490   0.000                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
sm_pp <- summary(aov(RDA_cor_RDA20000salpredict_salPhen~ subsamp_corr_phen_sal + demog_level + demog_level_sub + arch + demog_level*demog_level_sub*arch, data=final.df))
sm_pp
##                                    Df Sum Sq Mean Sq  F value   Pr(>F)    
## subsamp_corr_phen_sal               1  8.583   8.583 8167.415  < 2e-16 ***
## demog_level                         2  0.499   0.249  237.396  < 2e-16 ***
## demog_level_sub                     4  3.550   0.887  844.434  < 2e-16 ***
## arch                               11  0.076   0.007    6.591 7.49e-11 ***
## demog_level:demog_level_sub         8  1.187   0.148  141.149  < 2e-16 ***
## demog_level:arch                   22  0.071   0.003    3.057 2.49e-06 ***
## demog_level_sub:arch               44  0.085   0.002    1.830 0.000815 ***
## demog_level:demog_level_sub:arch   88  0.176   0.002    1.900 1.93e-06 ***
## Residuals                        1619  1.701   0.001                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 450 observations deleted due to missingness
 # Calculate proportion of variance explained in SS
 z<- data.frame(
        PropVarTempMutPred = round(tm_me[[1]][,2]/sum(tm_me[[1]][,2]), 2),
        PropVarTempPhenPred = round(tm_pp[[1]][,2]/sum(tm_pp[[1]][,2]), 2),
        PropVarEnv2MutPred = round(sm_me[[1]][,2]/sum(sm_me[[1]][,2]), 2),
        PropVarEnv2PhenPred = round(sm_pp[[1]][,2]/sum(sm_pp[[1]][,2]), 2))
  # note the the 1st row is specific for each trait, I just took a shortcut for labeling the rowname
 rownames(z) <- rownames(tm_me[[1]])

 z
##                                  PropVarTempMutPred PropVarTempPhenPred
## subsamp_corr_phen_temp                         0.03                0.93
## demog_level                                    0.06                0.00
## demog_level_sub                                0.01                0.02
## arch                                           0.63                0.00
## demog_level:demog_level_sub                    0.00                0.00
## demog_level:arch                               0.01                0.00
## demog_level_sub:arch                           0.02                0.00
## demog_level:demog_level_sub:arch               0.02                0.00
## Residuals                                      0.23                0.03
##                                  PropVarEnv2MutPred PropVarEnv2PhenPred
## subsamp_corr_phen_temp                         0.01                0.54
## demog_level                                    0.11                0.03
## demog_level_sub                                0.04                0.22
## arch                                           0.34                0.00
## demog_level:demog_level_sub                    0.02                0.07
## demog_level:arch                               0.10                0.00
## demog_level_sub:arch                           0.02                0.01
## demog_level:demog_level_sub:arch               0.03                0.01
## Residuals                                      0.33                0.11

The models clarify how the architecture determines the proportion of clines - architecture also largely determines how accurate the mutation prediction is - yet the RDA phenotype prediction is not sensitive to the architecture and it is driven more by how correlated the phenotype is with the environment.

Interesting sims to look at

This code just copies some of the figures into a new folder that I can download from the cluster.

RDA predictions as a function of the number of loci and structure correction

rdapred <- read.table("summary_20220428_20220726_RDApredictions.txt", header=TRUE)
head(rdapred)
##   i nloci Random_cor_RDAtemppredict_tempphen Random_cor_RDAsalpredict_salphen
## 1 1    10                          0.4739758                               NA
## 2 2    50                          0.7151539                               NA
## 3 3   100                          0.7974522                               NA
## 4 4   500                          0.8329278                               NA
## 5 5  5000                          0.8513302                               NA
## 6 6 20000                          0.8530879                               NA
##   Random_cor_RDAtemppredict_tempphen_structcorr
## 1                                   0.042232275
## 2                                   0.019313333
## 3                                  -0.001635637
## 4                                  -0.039277317
## 5                                  -0.033347381
## 6                                  -0.035417453
##   Random_cor_RDAsalpredict_salphen_structcorr    seed
## 1                                          NA 1231094
## 2                                          NA 1231094
## 3                                          NA 1231094
## 4                                          NA 1231094
## 5                                          NA 1231094
## 6                                          NA 1231094
rdapred_df <- merge(rdapred, final.df, by="seed", all.x=TRUE)
head(rdapred_df)
##      seed i nloci Random_cor_RDAtemppredict_tempphen
## 1 1231094 1    10                          0.4739758
## 2 1231094 2    50                          0.7151539
## 3 1231094 3   100                          0.7974522
## 4 1231094 4   500                          0.8329278
## 5 1231094 5  5000                          0.8513302
## 6 1231094 6 20000                          0.8530879
##   Random_cor_RDAsalpredict_salphen
## 1                               NA
## 2                               NA
## 3                               NA
## 4                               NA
## 5                               NA
## 6                               NA
##   Random_cor_RDAtemppredict_tempphen_structcorr
## 1                                   0.042232275
## 2                                   0.019313333
## 3                                  -0.001635637
## 4                                  -0.039277317
## 5                                  -0.033347381
## 6                                  -0.035417453
##   Random_cor_RDAsalpredict_salphen_structcorr
## 1                                          NA
## 2                                          NA
## 3                                          NA
## 4                                          NA
## 5                                          NA
## 6                                          NA
##                                                                    level reps
## 1 highly-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant    1
## 2 highly-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant    1
## 3 highly-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant    1
## 4 highly-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant    1
## 5 highly-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant    1
## 6 highly-polygenic_1-trait__Est-Clines_N-cline-center-to-edge_m-constant    1
##                       arch                                   demog_name
## 1 highly-polygenic_1-trait Est-Clines_N-cline-center-to-edge_m-constant
## 2 highly-polygenic_1-trait Est-Clines_N-cline-center-to-edge_m-constant
## 3 highly-polygenic_1-trait Est-Clines_N-cline-center-to-edge_m-constant
## 4 highly-polygenic_1-trait Est-Clines_N-cline-center-to-edge_m-constant
## 5 highly-polygenic_1-trait Est-Clines_N-cline-center-to-edge_m-constant
## 6 highly-polygenic_1-trait Est-Clines_N-cline-center-to-edge_m-constant
##               demog_level_sub demog_level MIG_x MIG_y xcline ycline   demog
## 1 N central cline\nm constant  Est-Clines  0.49  0.07 linear linear Estuary
## 2 N central cline\nm constant  Est-Clines  0.49  0.07 linear linear Estuary
## 3 N central cline\nm constant  Est-Clines  0.49  0.07 linear linear Estuary
## 4 N central cline\nm constant  Est-Clines  0.49  0.07 linear linear Estuary
## 5 N central cline\nm constant  Est-Clines  0.49  0.07 linear linear Estuary
## 6 N central cline\nm constant  Est-Clines  0.49  0.07 linear linear Estuary
##   METAPOP_SIDE_x METAPOP_SIDE_y Nequal isVariableM MIG_breaks arch_level_sub
## 1             10             10      4           0          0        1 trait
## 2             10             10      4           0          0        1 trait
## 3             10             10      4           0          0        1 trait
## 4             10             10      4           0          0        1 trait
## 5             10             10      4           0          0        1 trait
## 6             10             10      4           0          0        1 trait
##          arch_level MU_base MU_QTL_proportion SIGMA_QTN_1 SIGMA_QTN_2 SIGMA_K_1
## 1 highly\npolygenic   1e-07              0.25       0.002       0.002       0.5
## 2 highly\npolygenic   1e-07              0.25       0.002       0.002       0.5
## 3 highly\npolygenic   1e-07              0.25       0.002       0.002       0.5
## 4 highly\npolygenic   1e-07              0.25       0.002       0.002       0.5
## 5 highly\npolygenic   1e-07              0.25       0.002       0.002       0.5
## 6 highly\npolygenic   1e-07              0.25       0.002       0.002       0.5
##   SIGMA_K_2 N_traits  ispleiotropy n_samp_tot n_samp_per_pop
## 1       0.5        1 No pleiotropy       1000             10
## 2       0.5        1 No pleiotropy       1000             10
## 3       0.5        1 No pleiotropy       1000             10
## 4       0.5        1 No pleiotropy       1000             10
## 5       0.5        1 No pleiotropy       1000             10
## 6       0.5        1 No pleiotropy       1000             10
##   sd_fitness_among_inds sd_fitness_among_pops final_LA K   Bonf_alpha
## 1            0.05272602            0.01977273 0.500854 2 1.918428e-06
## 2            0.05272602            0.01977273 0.500854 2 1.918428e-06
## 3            0.05272602            0.01977273 0.500854 2 1.918428e-06
## 4            0.05272602            0.01977273 0.500854 2 1.918428e-06
## 5            0.05272602            0.01977273 0.500854 2 1.918428e-06
## 6            0.05272602            0.01977273 0.500854 2 1.918428e-06
##   numCausalLowMAFsample all_corr_phen_temp subsamp_corr_phen_temp
## 1                    39           0.954579              0.8893387
## 2                    39           0.954579              0.8893387
## 3                    39           0.954579              0.8893387
## 4                    39           0.954579              0.8893387
## 5                    39           0.954579              0.8893387
## 6                    39           0.954579              0.8893387
##   all_corr_phen_sal subsamp_corr_phen_sal num_causal_prefilter
## 1                NA                    NA                 2628
## 2                NA                    NA                 2628
## 3                NA                    NA                 2628
## 4                NA                    NA                 2628
## 5                NA                    NA                 2628
## 6                NA                    NA                 2628
##   num_causal_postfilter num_non_causal num_neut_prefilter num_neut_postfilter
## 1                   310          25753              26587               26587
## 2                   310          25753              26587               26587
## 3                   310          25753              26587               26587
## 4                   310          25753              26587               26587
## 5                   310          25753              26587               26587
## 6                   310          25753              26587               26587
##   num_neut_neutralgenome num_causal_temp num_causal_sal num_multiallelic
## 1                  12867             310              0                0
## 2                  12867             310              0                0
## 3                  12867             310              0                0
## 4                  12867             310              0                0
## 5                  12867             310              0                0
## 6                  12867             310              0                0
##     meanFst va_temp_total va_sal_total Va_temp_sample Va_sal_sample nSNPs
## 1 0.1803949    0.01185008            0     0.01356519             0 26063
## 2 0.1803949    0.01185008            0     0.01356519             0 26063
## 3 0.1803949    0.01185008            0     0.01356519             0 26063
## 4 0.1803949    0.01185008            0     0.01356519             0 26063
## 5 0.1803949    0.01185008            0     0.01356519             0 26063
## 6 0.1803949    0.01185008            0     0.01356519             0 26063
##   median_causal_temp_cor median_causal_sal_cor median_neut_temp_cor
## 1              0.3580437                    NA            0.3820531
## 2              0.3580437                    NA            0.3820531
## 3              0.3580437                    NA            0.3820531
## 4              0.3580437                    NA            0.3820531
## 5              0.3580437                    NA            0.3820531
## 6              0.3580437                    NA            0.3820531
##   median_neut_sal_cor cor_VA_temp_prop cor_VA_sal_prop cor_TPR_temp cor_TPR_sal
## 1          0.04816897        0.8451605               0    0.4612903          NA
## 2          0.04816897        0.8451605               0    0.4612903          NA
## 3          0.04816897        0.8451605               0    0.4612903          NA
## 4          0.04816897        0.8451605               0    0.4612903          NA
## 5          0.04816897        0.8451605               0    0.4612903          NA
## 6          0.04816897        0.8451605               0    0.4612903          NA
##   cor_FDR_allSNPs_temp cor_FDR_neutSNPs_temp cor_FDR_allSNPs_sal
## 1            0.9894449             0.9791241                  NA
## 2            0.9894449             0.9791241                  NA
## 3            0.9894449             0.9791241                  NA
## 4            0.9894449             0.9791241                  NA
## 5            0.9894449             0.9791241                  NA
## 6            0.9894449             0.9791241                  NA
##   cor_FDR_neutSNPs_sal num_causal_sig_temp_corr num_causal_sig_sal_corr
## 1                   NA                      143                       0
## 2                   NA                      143                       0
## 3                   NA                      143                       0
## 4                   NA                      143                       0
## 5                   NA                      143                       0
## 6                   NA                      143                       0
##   num_notCausal_sig_temp_corr num_notCausal_sig_sal_corr num_neut_sig_temp_corr
## 1                       13405                          0                   6707
## 2                       13405                          0                   6707
## 3                       13405                          0                   6707
## 4                       13405                          0                   6707
## 5                       13405                          0                   6707
## 6                       13405                          0                   6707
##   num_neut_sig_sal_corr cor_AUCPR_temp_allSNPs cor_AUCPR_temp_neutSNPs
## 1                     0             0.01064045              0.02148047
## 2                     0             0.01064045              0.02148047
## 3                     0             0.01064045              0.02148047
## 4                     0             0.01064045              0.02148047
## 5                     0             0.01064045              0.02148047
## 6                     0             0.01064045              0.02148047
##   cor_AUCPR_sal_allSNPs cor_AUCPR_sal_neutSNPs cor_af_temp_noutliers
## 1                    NA                     NA                 13548
## 2                    NA                     NA                 13548
## 3                    NA                     NA                 13548
## 4                    NA                     NA                 13548
## 5                    NA                     NA                 13548
## 6                    NA                     NA                 13548
##   cor_af_sal_noutliers cor_FPR_temp_neutSNPs cor_FPR_sal_neutSNPs
## 1                    0             0.5212559                    0
## 2                    0             0.5212559                    0
## 3                    0             0.5212559                    0
## 4                    0             0.5212559                    0
## 5                    0             0.5212559                    0
## 6                    0             0.5212559                    0
##   LEA3.2_lfmm2_Va_temp_prop LEA3.2_lfmm2_Va_sal_prop LEA3.2_lfmm2_TPR_temp
## 1                  0.278265                       NA            0.02258065
## 2                  0.278265                       NA            0.02258065
## 3                  0.278265                       NA            0.02258065
## 4                  0.278265                       NA            0.02258065
## 5                  0.278265                       NA            0.02258065
## 6                  0.278265                       NA            0.02258065
##   LEA3.2_lfmm2_TPR_sal LEA3.2_lfmm2_FDR_allSNPs_temp
## 1                   NA                      0.978979
## 2                   NA                      0.978979
## 3                   NA                      0.978979
## 4                   NA                      0.978979
## 5                   NA                      0.978979
## 6                   NA                      0.978979
##   LEA3.2_lfmm2_FDR_allSNPs_sal LEA3.2_lfmm2_FDR_neutSNPs_temp
## 1                           NA                      0.9263158
## 2                           NA                      0.9263158
## 3                           NA                      0.9263158
## 4                           NA                      0.9263158
## 5                           NA                      0.9263158
## 6                           NA                      0.9263158
##   LEA3.2_lfmm2_FDR_neutSNPs_sal LEA3.2_lfmm2_AUCPR_temp_allSNPs
## 1                            NA                      0.01339495
## 2                            NA                      0.01339495
## 3                            NA                      0.01339495
## 4                            NA                      0.01339495
## 5                            NA                      0.01339495
## 6                            NA                      0.01339495
##   LEA3.2_lfmm2_AUCPR_temp_neutSNPs LEA3.2_lfmm2_AUCPR_sal_allSNPs
## 1                       0.02655237                             NA
## 2                       0.02655237                             NA
## 3                       0.02655237                             NA
## 4                       0.02655237                             NA
## 5                       0.02655237                             NA
## 6                       0.02655237                             NA
##   LEA3.2_lfmm2_AUCPR_sal_neutSNPs LEA3.2_lfmm2_mlog10P_tempenv_noutliers
## 1                              NA                                    333
## 2                              NA                                    333
## 3                              NA                                    333
## 4                              NA                                    333
## 5                              NA                                    333
## 6                              NA                                    333
##   LEA3.2_lfmm2_mlog10P_salenv_noutliers LEA3.2_lfmm2_num_causal_sig_temp
## 1                                     0                                7
## 2                                     0                                7
## 3                                     0                                7
## 4                                     0                                7
## 5                                     0                                7
## 6                                     0                                7
##   LEA3.2_lfmm2_num_neut_sig_temp LEA3.2_lfmm2_num_causal_sig_sal
## 1                             88                               0
## 2                             88                               0
## 3                             88                               0
## 4                             88                               0
## 5                             88                               0
## 6                             88                               0
##   LEA3.2_lfmm2_num_neut_sig_sal LEA3.2_lfmm2_FPR_neutSNPs_temp
## 1                             0                    0.006839201
## 2                             0                    0.006839201
## 3                             0                    0.006839201
## 4                             0                    0.006839201
## 5                             0                    0.006839201
## 6                             0                    0.006839201
##   LEA3.2_lfmm2_FPR_neutSNPs_sal RDA1_propvar RDA2_propvar RDA1_propvar_corr
## 1                             0        0.985        0.015             0.765
## 2                             0        0.985        0.015             0.765
## 3                             0        0.985        0.015             0.765
## 4                             0        0.985        0.015             0.765
## 5                             0        0.985        0.015             0.765
## 6                             0        0.985        0.015             0.765
##   RDA2_propvar_corr RDA1_temp_cor RDA1_sal_cor RDA2_temp_cor RDA2_sal_cor
## 1             0.235     0.9999982  0.001912722  -0.001912722    0.9999982
## 2             0.235     0.9999982  0.001912722  -0.001912722    0.9999982
## 3             0.235     0.9999982  0.001912722  -0.001912722    0.9999982
## 4             0.235     0.9999982  0.001912722  -0.001912722    0.9999982
## 5             0.235     0.9999982  0.001912722  -0.001912722    0.9999982
## 6             0.235     0.9999982  0.001912722  -0.001912722    0.9999982
##   RDA_Va_temp_prop RDA_Va_temp_prop_corr RDA_Va_sal_prop RDA_Va_sal_prop_corr
## 1        0.1248244                     0               0                    0
## 2        0.1248244                     0               0                    0
## 3        0.1248244                     0               0                    0
## 4        0.1248244                     0               0                    0
## 5        0.1248244                     0               0                    0
## 6        0.1248244                     0               0                    0
##       RDA_TPR RDA_TPR_corr RDA_FDR_allSNPs RDA_FDR_allSNPs_corr
## 1 0.006451613            0       0.9918699                    1
## 2 0.006451613            0       0.9918699                    1
## 3 0.006451613            0       0.9918699                    1
## 4 0.006451613            0       0.9918699                    1
## 5 0.006451613            0       0.9918699                    1
## 6 0.006451613            0       0.9918699                    1
##   num_RDA_sig_causal num_RDA_sig_neutral num_RDA_sig_causal_corr
## 1                  2                 118                       0
## 2                  2                 118                       0
## 3                  2                 118                       0
## 4                  2                 118                       0
## 5                  2                 118                       0
## 6                  2                 118                       0
##   num_RDA_sig_neutral_corr RDA_FDR_neutSNPs RDA_FDR_neutSNPs_corr
## 1                      200        0.9833333                     1
## 2                      200        0.9833333                     1
## 3                      200        0.9833333                     1
## 4                      200        0.9833333                     1
## 5                      200        0.9833333                     1
## 6                      200        0.9833333                     1
##   RDA_AUCPR_allSNPs RDA_AUCPR_neutSNPs RDA_AUCPR_neutSNPs_corr RDA_FPR_neutSNPs
## 1       0.008249728         0.01647883              0.01597697      0.009170747
## 2       0.008249728         0.01647883              0.01597697      0.009170747
## 3       0.008249728         0.01647883              0.01597697      0.009170747
## 4       0.008249728         0.01647883              0.01597697      0.009170747
## 5       0.008249728         0.01647883              0.01597697      0.009170747
## 6       0.008249728         0.01647883              0.01597697      0.009170747
##   RDA_FPR_neutSNPs_corr RDA_RDAmutpred_cor_tempEffect
## 1            0.01554364                     0.2566239
## 2            0.01554364                     0.2566239
## 3            0.01554364                     0.2566239
## 4            0.01554364                     0.2566239
## 5            0.01554364                     0.2566239
## 6            0.01554364                     0.2566239
##   RDA_RDAmutpred_cor_salEffect RDA_absRDAmutpred_cor_tempVa
## 1                           NA                  -0.04251831
## 2                           NA                  -0.04251831
## 3                           NA                  -0.04251831
## 4                           NA                  -0.04251831
## 5                           NA                  -0.04251831
## 6                           NA                  -0.04251831
##   RDA_absRDAmutpred_cor_salVa RDA_RDAmutpred_cor_tempEffect_structcorr
## 1                          NA                                0.1711607
## 2                          NA                                0.1711607
## 3                          NA                                0.1711607
## 4                          NA                                0.1711607
## 5                          NA                                0.1711607
## 6                          NA                                0.1711607
##   RDA_RDAmutpred_cor_salEffect_structcorr
## 1                                      NA
## 2                                      NA
## 3                                      NA
## 4                                      NA
## 5                                      NA
## 6                                      NA
##   RDA_absRDAmutpred_cor_tempVa_structcorr
## 1                             0.002950593
## 2                             0.002950593
## 3                             0.002950593
## 4                             0.002950593
## 5                             0.002950593
## 6                             0.002950593
##   RDA_absRDAmutpred_cor_salVa_structcorr RDA_cor_RDA20000temppredict_tempPhen
## 1                                     NA                            0.8530879
## 2                                     NA                            0.8530879
## 3                                     NA                            0.8530879
## 4                                     NA                            0.8530879
## 5                                     NA                            0.8530879
## 6                                     NA                            0.8530879
##   RDA_cor_RDA20000salpredict_salPhen
## 1                                 NA
## 2                                 NA
## 3                                 NA
## 4                                 NA
## 5                                 NA
## 6                                 NA
##   RDA_cor_RDA20000temppredict_tempPhen_structcorr
## 1                                     -0.03541745
## 2                                     -0.03541745
## 3                                     -0.03541745
## 4                                     -0.03541745
## 5                                     -0.03541745
## 6                                     -0.03541745
##   RDA_cor_RDA20000salpredict_salPhen_structcorr cor_PC1_temp  cor_PC1_sal
## 1                                            NA   -0.9938219 -0.002423473
## 2                                            NA   -0.9938219 -0.002423473
## 3                                            NA   -0.9938219 -0.002423473
## 4                                            NA   -0.9938219 -0.002423473
## 5                                            NA   -0.9938219 -0.002423473
## 6                                            NA   -0.9938219 -0.002423473
##   cor_PC2_temp cor_PC2_sal cor_LFMMU1_temp cor_LFMMU1_sal cor_LFMMU2_temp
## 1  -0.02040717 -0.00168847       0.0702796   -0.001851458      -0.2374149
## 2  -0.02040717 -0.00168847       0.0702796   -0.001851458      -0.2374149
## 3  -0.02040717 -0.00168847       0.0702796   -0.001851458      -0.2374149
## 4  -0.02040717 -0.00168847       0.0702796   -0.001851458      -0.2374149
## 5  -0.02040717 -0.00168847       0.0702796   -0.001851458      -0.2374149
## 6  -0.02040717 -0.00168847       0.0702796   -0.001851458      -0.2374149
##   cor_LFMMU2_sal cor_PC1_LFMMU1_temp cor_PC1_LFMMU1_sal cor_PC2_LFMMU1_temp
## 1   -0.002823011         -0.09231664          0.9995526           0.9926958
## 2   -0.002823011         -0.09231664          0.9995526           0.9926958
## 3   -0.002823011         -0.09231664          0.9995526           0.9926958
## 4   -0.002823011         -0.09231664          0.9995526           0.9926958
## 5   -0.002823011         -0.09231664          0.9995526           0.9926958
## 6   -0.002823011         -0.09231664          0.9995526           0.9926958
##   cor_PC2_LFMMU1_sal gwas_TPR_sal gwas_TPR_temp gwas_FDR_sal_neutbase
## 1        0.001339894           NA     0.2290323                    NA
## 2        0.001339894           NA     0.2290323                    NA
## 3        0.001339894           NA     0.2290323                    NA
## 4        0.001339894           NA     0.2290323                    NA
## 5        0.001339894           NA     0.2290323                    NA
## 6        0.001339894           NA     0.2290323                    NA
##   gwas_FDR_temp_neutbase clinalparadigm_sal_proptop5GWASclines
## 1              0.9667914                                    NA
## 2              0.9667914                                    NA
## 3              0.9667914                                    NA
## 4              0.9667914                                    NA
## 5              0.9667914                                    NA
## 6              0.9667914                                    NA
##   clinalparadigm_temp_proptop5GWASclines clinalparadigm_sal_propsigGWASclines
## 1                              0.6554106                                   NA
## 2                              0.6554106                                   NA
## 3                              0.6554106                                   NA
## 4                              0.6554106                                   NA
## 5                              0.6554106                                   NA
## 6                              0.6554106                                   NA
##   clinalparadigm_temp_propsigGWASclines N_traits2 change_temp_mut
## 1                             0.6050302   1 Trait     -0.08546318
## 2                             0.6050302   1 Trait     -0.08546318
## 3                             0.6050302   1 Trait     -0.08546318
## 4                             0.6050302   1 Trait     -0.08546318
## 5                             0.6050302   1 Trait     -0.08546318
## 6                             0.6050302   1 Trait     -0.08546318
##   change_sal_mut change_temp change_sal
## 1             NA  -0.8885054         NA
## 2             NA  -0.8885054         NA
## 3             NA  -0.8885054         NA
## 4             NA  -0.8885054         NA
## 5             NA  -0.8885054         NA
## 6             NA  -0.8885054         NA
rdapred_df$SIGMA_K_2 <- as.factor(as.character(rdapred_df$SIGMA_K_2))

rdapred_df1 <-  filter(rdapred_df, nloci %in% c(10,50,500,5000,20000))

r1<- ggplot(rdapred_df1 ) +
  geom_line( aes(x=nloci, y=Random_cor_RDAtemppredict_tempphen, group=seed, color=SIGMA_K_2), alpha=0.1, linetype="dashed") + facet_wrap(~arch_level) + ggtheme + ylim(-1,1) + ylab("Accuracy of RDA prediction\nTemperature trait\n worse <<--->> better")  + theme(legend.position = "none") + ggtitle("A) Temperature trait")  + stat_summary(aes(x=nloci, y=Random_cor_RDAtemppredict_tempphen, color=SIGMA_K_2),  size=2,geom="line", fun="mean")  + xlab("Number of random loci from genome") + theme(axis.text.x = element_text(angle = 60, vjust=1, hjust=1))
r1

r2 <- ggplot(rdapred_df1) + 
  geom_line(aes(x=nloci, y=Random_cor_RDAtemppredict_tempphen_structcorr, group=seed, color=SIGMA_K_2), alpha=0.1, linetype="dashed") + facet_wrap(~arch_level) + ggtheme + ylim(-1,1)+ ylab("Accuracy of structure-\ncorrected RDA prediction\nTemperature trait\n worse <<--->> better") + ggtitle("B) Temperature trait with structure correction")+ guides(color=guide_legend(title="Strength of\nstabilizing\nselection"))   + xlab("Number of random loci from genome") + theme(axis.text.x = element_text(angle = 60, vjust=1, hjust=1)) + stat_summary(aes(x=nloci, y=Random_cor_RDAtemppredict_tempphen_structcorr, color=SIGMA_K_2),  size=2,geom="line", fun="mean")  + xlab("Number of random loci from genome") + scale_color_hue(labels=c(expression(paste("Strong ", sigma[K]," = 0.5")), 
  expression(paste("Weak ", sigma[K]," = 4.0"))))
r2

r3 <- ggplot(rdapred_df1) + 
  geom_line(aes(x=nloci, y=Random_cor_RDAsalpredict_salphen, group=seed, color=as.factor(demog_level)), alpha=0.1,  linetype="dashed") + facet_wrap(~arch_level) + ggtheme + ylim(-1,1) + ylab("Accuracy of RDA prediction\nEnv2 trait\n worse <<--->> better")  + theme(legend.position = "none") + ggtitle("C) Env2 trait") + stat_summary(aes(x=nloci, y=Random_cor_RDAsalpredict_salphen, color=as.factor(demog_level)),  size=2,geom="line", fun="mean")  + xlab("Number of random loci from genome") + theme(axis.text.x = element_text(angle = 60, vjust=1, hjust=1))
r3
## Warning: Removed 2160 rows containing non-finite values (stat_summary).
## Warning: Removed 2160 row(s) containing missing values (geom_path).

r4 <- ggplot(rdapred_df1) + 
  geom_line(aes(x=nloci, y=Random_cor_RDAsalpredict_salphen_structcorr, group=seed, color=as.factor(demog_level)), alpha=0.1, linetype="dashed") + facet_wrap(~arch_level) + ggtheme + ylim(-1,1) + ylab("Accuracy of structure-\ncorrected RDA prediction\nEnv2 trait\n worse <<--->> better") + ggtitle("D) Env2 trait with structure correction")  + guides(color=guide_legend(title="Landscape")) + stat_summary(aes(x=nloci, y=Random_cor_RDAsalpredict_salphen_structcorr, color=as.factor(demog_level)),  size=2,geom="line", fun="mean") + xlab("Number of random loci from genome") + theme(axis.text.x = element_text(angle = 60, vjust=1, hjust=1))
r4
## Warning: Removed 2160 rows containing non-finite values (stat_summary).

## Warning: Removed 2160 row(s) containing missing values (geom_path).

pdf(paste0(outputs,"RDApredictionFunctionOfnLoci.pdf"), width=12, height=8)  
grid.arrange(r1,r2, r3, r4, nrow=2, layout_matrix=matrix(c(1,1,1,1,2,2,2,2,2
                                                           ,3,3,3,3,4,4,4,4,4),
                                                         nrow=2, byrow=TRUE)
             )
## Warning: Removed 2160 rows containing non-finite values (stat_summary).

## Warning: Removed 2160 row(s) containing missing values (geom_path).
## Warning: Removed 2160 rows containing non-finite values (stat_summary).
## Warning: Removed 2160 row(s) containing missing values (geom_path).
#missing values from simulations with low diversity that were filtered out
dev.off()
## svg 
##   2
# removed rows expected based on single-trait simulations

Accuracy of RDA trait prediction as a function of the number of QTN loci in the simulation and strength of selection on the trait. The strength of selection on the trait also determines the strength of selection on the QTN loci in the architecture, how strongly they respond to selection, and the amount of LD around them when they sweep to high frequency in a deme or set of demes.

head(rdapred_df1[,40:50])
##     Bonf_alpha numCausalLowMAFsample all_corr_phen_temp subsamp_corr_phen_temp
## 1 1.918428e-06                    39          0.9545790              0.8893387
## 2 1.918428e-06                    39          0.9545790              0.8893387
## 3 1.918428e-06                    39          0.9545790              0.8893387
## 4 1.918428e-06                    39          0.9545790              0.8893387
## 5 1.918428e-06                    39          0.9545790              0.8893387
## 6 1.730523e-06                   104          0.9545764              0.9006961
##   all_corr_phen_sal subsamp_corr_phen_sal num_causal_prefilter
## 1                NA                    NA                 2628
## 2                NA                    NA                 2628
## 3                NA                    NA                 2628
## 4                NA                    NA                 2628
## 5                NA                    NA                 2628
## 6                NA                    NA                 3144
##   num_causal_postfilter num_non_causal num_neut_prefilter num_neut_postfilter
## 1                   310          25753              26587               26587
## 2                   310          25753              26587               26587
## 3                   310          25753              26587               26587
## 4                   310          25753              26587               26587
## 5                   310          25753              26587               26587
## 6                   382          28511              30284               30284
final.df$SIGMA_K_2 <- as.factor(final.df$SIGMA_K_2)
levels(final.df$demog_level_sub)
## [1] "N equal\nm constant"          "N equal\nm breaks"           
## [3] "N latitude cline\nm constant" "N central cline\nm constant" 
## [5] "N variable\nm variable"
# Remove the demography that had the worse performance in Env2
# so as not to bias the loess smoother

final.df1 <- final.df %>% filter(demog_level_sub != "N variable\nm variable")

rr1 <- ggplot(final.df1) + geom_point(aes(x=num_causal_postfilter, y=RDA_cor_RDA20000temppredict_tempPhen, color=SIGMA_K_2), alpha=0.4) + 
  geom_smooth(aes(x=num_causal_postfilter, y=RDA_cor_RDA20000temppredict_tempPhen, color=SIGMA_K_2), method="loess", span=10) + scale_x_log10() + ylim(0,1) + ggtheme + ylab("Accuracy of RDA prediction\nTemperature trait\nworse <<--->> better") + guides(color=guide_legend(title="Strength of\nstabilizing\nselection")) + xlab("Number of evolved QTN loci") + ggtitle("A) Accuracy for Temp. trait") + scale_color_hue(labels=c(expression(paste("Strong ", sigma[K]," = 0.5")), 
  expression(paste("Weak ", sigma[K]," = 4.0"))))
rr1
## `geom_smooth()` using formula 'y ~ x'

rr2 <- ggplot(final.df1) + geom_point(aes(x=num_causal_postfilter, y=RDA_cor_RDA20000salpredict_salPhen, color=demog_level), alpha=0.4) + 
  geom_smooth(aes(x=num_causal_postfilter, y=RDA_cor_RDA20000salpredict_salPhen, color=demog_level), method="loess", span=20) + scale_x_log10() + ylim(0,1) + ggtheme + ylab("Accuracy of RDA prediction\nEnv2 trait\nworse <<--->> better") + guides(color=guide_legend(title="Landscape")) + xlab("Number of evolved QTN loci") + ggtitle("B) Accuracy for Env2 trait (always strong selection)") #missing values expected for Env2 trait because not under selection in all sims
rr2
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 360 rows containing non-finite values (stat_smooth).
## Warning: Removed 360 rows containing missing values (geom_point).

pdf(paste0(outputs,"RDAtraitpred_vs_nQTN.pdf"), width=10, height=5)
grid.arrange(rr1, rr2, nrow=1)
## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 360 rows containing non-finite values (stat_smooth).

## Warning: Removed 360 rows containing missing values (geom_point).
dev.off()
## svg 
##   2